Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pass tsconfig path to typescript parseJsonConfigFileContent #495

Merged
merged 11 commits into from
Sep 29, 2022
5 changes: 5 additions & 0 deletions .changeset/hip-flies-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

Pass config file path to typescript so relative paths are applied to correct directory
emmatown marked this conversation as resolved.
Show resolved Hide resolved
83 changes: 83 additions & 0 deletions packages/cli/src/build/__tests__/src-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import build from "../";
import { testdir, getDist, ts, repoNodeModules } from "../../../test-utils";

test("monorepo with root src dir and typescript package", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
name: "root",
devDependencies: {
typescript: "^3.8.3",
},
preconstruct: {
packages: ["src/packages/*"],
},
}),
".babelrc": JSON.stringify({
presets: [
require.resolve("@babel/preset-env"),
require.resolve("@babel/preset-typescript"),
],
}),
node_modules: {
kind: "symlink",
path: repoNodeModules,
},
"src/packages/my-package/package.json": JSON.stringify({
name: "my-package",
main: "dist/my-package.cjs.js",
module: "dist/my-package.esm.js",
}),
"src/packages/my-package/tsconfig.json": `{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "./build"
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true
}
}
`,

"src/packages/my-package/src/index.ts": ts`
export default {};
`,
});

await build(tmpPath);

expect(await getDist(tmpPath + "/src/packages/my-package"))
.toMatchInlineSnapshot(`
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/declarations/build/index.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
mycroes marked this conversation as resolved.
Show resolved Hide resolved
declare const _default: {};
export default _default;

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
export * from "./declarations/build/index";
export { default } from "./declarations/build/index";

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.dev.js, dist/my-package.cjs.prod.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var index = {};

exports.default = index;

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
'use strict';

if (process.env.NODE_ENV === "production") {
module.exports = require("./my-package.cjs.prod.js");
} else {
module.exports = require("./my-package.cjs.dev.js");
}

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.esm.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
var index = {};

export default index;

`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function nonMemoizedGetProgram(typescript: TS, configFileName: string) {
let thing = typescript.parseJsonConfigFileContent(
result.config,
typescript.sys,
process.cwd(),
path.dirname(configFileName),
undefined,
configFileName
);
Expand Down