-
Notifications
You must be signed in to change notification settings - Fork 59
/
src-root.ts
84 lines (70 loc) 路 2.48 KB
/
src-root.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
`);
});