Skip to content

Commit

Permalink
Ignore outDir and declarationDir in tsconfig (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
mycroes committed Sep 29, 2022
1 parent 0c79455 commit 4e90c2b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-flies-dance.md
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

The `outDir` and `declarationDir` tsconfig options are now ignored. These options are unnecessary for Preconstruct since it controls where the `.d.ts` files are emitted to. This fixes confusing errors if you had these options set.
84 changes: 84 additions & 0 deletions packages/cli/src/build/__tests__/src-root.ts
@@ -0,0 +1,84 @@
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/cjs",
"declarationDir": "./build/types",
"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/src/index.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
declare const _default: {};
export default _default;
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
export * from "./declarations/src/index";
export { default } from "./declarations/src/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;
`);
});
Expand Up @@ -96,6 +96,8 @@ async function nonMemoizedGetProgram(typescript: TS, configFileName: string) {
configFileName
);

thing.options.outDir = undefined;
thing.options.declarationDir = undefined;
thing.options.declaration = true;
thing.options.emitDeclarationOnly = true;
thing.options.noEmit = false;
Expand Down

0 comments on commit 4e90c2b

Please sign in to comment.