@mui/internal-code-infra 0.0.4-canary.5 → 0.0.4-canary.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +19 -8
- package/build/babel-config.d.mts +11 -3
- package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
- package/build/brokenLinksChecker/index.d.mts +45 -2
- package/build/changelog/types.d.ts +1 -1
- package/build/cli/cmdArgosPush.d.mts +2 -2
- package/build/cli/cmdBuild.d.mts +2 -2
- package/build/cli/cmdCopyFiles.d.mts +2 -2
- package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
- package/build/cli/cmdGenerateChangelog.d.mts +2 -2
- package/build/cli/cmdGithubAuth.d.mts +2 -2
- package/build/cli/cmdListWorkspaces.d.mts +4 -2
- package/build/cli/cmdNetlifyIgnore.d.mts +3 -2
- package/build/cli/cmdPublish.d.mts +4 -2
- package/build/cli/cmdPublishCanary.d.mts +3 -3
- package/build/cli/cmdPublishNewPackage.d.mts +4 -2
- package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
- package/build/cli/cmdVale.d.mts +46 -0
- package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
- package/build/eslint/baseConfig.d.mts +3 -1
- package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
- package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
- package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
- package/build/eslint/mui/rules/no-presentation-role.d.mts +5 -0
- package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
- package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
- package/build/markdownlint/duplicate-h1.d.mts +1 -1
- package/build/markdownlint/git-diff.d.mts +1 -1
- package/build/markdownlint/index.d.mts +1 -1
- package/build/markdownlint/straight-quotes.d.mts +1 -1
- package/build/markdownlint/table-alignment.d.mts +1 -1
- package/build/markdownlint/terminal-language.d.mts +1 -1
- package/build/remark/config.d.mts +43 -0
- package/build/remark/createLintTester.d.mts +10 -0
- package/build/remark/firstBlockHeading.d.mts +4 -0
- package/build/remark/gitDiff.d.mts +2 -0
- package/build/remark/noSpaceInLinks.d.mts +2 -0
- package/build/remark/straightQuotes.d.mts +2 -0
- package/build/remark/tableAlignment.d.mts +2 -0
- package/build/remark/terminalLanguage.d.mts +2 -0
- package/build/utils/babel.d.mts +1 -1
- package/build/utils/build.d.mts +4 -4
- package/build/utils/github.d.mts +1 -1
- package/build/utils/pnpm.d.mts +68 -2
- package/build/utils/testUtils.d.mts +7 -0
- package/build/utils/typescript.d.mts +2 -2
- package/package.json +62 -35
- package/src/babel-config.mjs +9 -3
- package/src/brokenLinksChecker/__fixtures__/static-site/index.html +1 -0
- package/src/brokenLinksChecker/__fixtures__/static-site/invalid-html.html +15 -0
- package/src/brokenLinksChecker/crawlWorker.mjs +217 -0
- package/src/brokenLinksChecker/index.mjs +217 -164
- package/src/brokenLinksChecker/index.test.ts +50 -13
- package/src/changelog/categorizeCommits.test.ts +5 -5
- package/src/changelog/fetchChangelogs.mjs +6 -2
- package/src/changelog/parseCommitLabels.test.ts +5 -5
- package/src/changelog/renderChangelog.mjs +1 -1
- package/src/changelog/types.ts +1 -1
- package/src/cli/cmdListWorkspaces.mjs +9 -2
- package/src/cli/cmdNetlifyIgnore.mjs +35 -93
- package/src/cli/cmdPublish.mjs +51 -14
- package/src/cli/cmdPublishCanary.mjs +128 -132
- package/src/cli/cmdPublishNewPackage.mjs +27 -6
- package/src/cli/cmdVale.mjs +513 -0
- package/src/cli/cmdVale.test.mjs +644 -0
- package/src/cli/index.mjs +2 -0
- package/src/cli/packageJson.d.ts +1 -1
- package/src/eslint/baseConfig.mjs +45 -20
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/jsonConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +21 -1
- package/src/eslint/mui/index.mjs +4 -0
- package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
- package/src/eslint/mui/rules/no-guarded-throw.test.mjs +206 -0
- package/src/eslint/mui/rules/no-presentation-role.mjs +60 -0
- package/src/eslint/mui/rules/no-presentation-role.test.mjs +33 -0
- package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
- package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
- package/src/eslint/testConfig.mjs +2 -1
- package/src/estree-typescript.d.ts +1 -1
- package/src/remark/config.mjs +157 -0
- package/src/remark/createLintTester.mjs +19 -0
- package/src/remark/firstBlockHeading.mjs +87 -0
- package/src/remark/firstBlockHeading.test.mjs +107 -0
- package/src/remark/gitDiff.mjs +43 -0
- package/src/remark/gitDiff.test.mjs +45 -0
- package/src/remark/noSpaceInLinks.mjs +42 -0
- package/src/remark/noSpaceInLinks.test.mjs +22 -0
- package/src/remark/straightQuotes.mjs +31 -0
- package/src/remark/straightQuotes.test.mjs +25 -0
- package/src/remark/tableAlignment.mjs +23 -0
- package/src/remark/tableAlignment.test.mjs +28 -0
- package/src/remark/terminalLanguage.mjs +19 -0
- package/src/remark/terminalLanguage.test.mjs +17 -0
- package/src/untyped-plugins.d.ts +11 -11
- package/src/utils/build.mjs +18 -1
- package/src/utils/build.test.mjs +585 -575
- package/src/utils/pnpm.mjs +192 -3
- package/src/utils/pnpm.test.mjs +580 -0
- package/src/utils/testUtils.mjs +18 -0
- package/src/utils/typescript.test.mjs +249 -272
- package/vale/.vale.ini +1 -0
- package/vale/styles/MUI/CorrectReferenceAllCases.yml +43 -0
- package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
- package/vale/styles/MUI/GoogleLatin.yml +11 -0
- package/vale/styles/MUI/MuiBrandName.yml +22 -0
- package/vale/styles/MUI/NoBritish.yml +112 -0
- package/vale/styles/MUI/NoCompanyName.yml +17 -0
package/src/utils/build.test.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import * as os from 'node:os';
|
|
3
2
|
import * as path from 'node:path';
|
|
4
3
|
import { describe, expect, it } from 'vitest';
|
|
5
4
|
|
|
5
|
+
import { makeTempDir } from './testUtils.mjs';
|
|
6
6
|
import { createPackageBin, createPackageExports } from './build.mjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -14,21 +14,149 @@ async function createFile(filePath, contents = '') {
|
|
|
14
14
|
await fs.writeFile(filePath, contents, 'utf8');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* @param {(cwd: string) => Promise<void>} fn
|
|
19
|
-
*/
|
|
20
|
-
async function withTempDir(fn) {
|
|
21
|
-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'code-infra-build-test-'));
|
|
22
|
-
try {
|
|
23
|
-
return await fn(tmpDir);
|
|
24
|
-
} finally {
|
|
25
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
17
|
describe('createPackageExports', () => {
|
|
18
|
+
it('always puts import before require regardless of bundle array order', async () => {
|
|
19
|
+
const cwd = await makeTempDir();
|
|
20
|
+
const outputDir = path.join(cwd, 'build');
|
|
21
|
+
|
|
22
|
+
await Promise.all([
|
|
23
|
+
createFile(path.join(cwd, 'src/index.ts')),
|
|
24
|
+
createFile(path.join(cwd, 'src/feature.ts')),
|
|
25
|
+
createFile(path.join(outputDir, 'index.js')),
|
|
26
|
+
createFile(path.join(outputDir, 'index.cjs')),
|
|
27
|
+
createFile(path.join(outputDir, 'feature.js')),
|
|
28
|
+
createFile(path.join(outputDir, 'feature.cjs')),
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
// Pass cjs before esm to verify the key order is still 'import' then 'require'
|
|
32
|
+
const { exports: packageExports } = await createPackageExports({
|
|
33
|
+
exports: {
|
|
34
|
+
'.': './src/index.ts',
|
|
35
|
+
'./feature': './src/feature.ts',
|
|
36
|
+
},
|
|
37
|
+
bundles: [
|
|
38
|
+
{ type: 'cjs', dir: '.' },
|
|
39
|
+
{ type: 'esm', dir: '.' },
|
|
40
|
+
],
|
|
41
|
+
outputDir,
|
|
42
|
+
cwd,
|
|
43
|
+
isFlat: true,
|
|
44
|
+
packageType: 'module',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(Object.keys(/** @type {Record<string, unknown>} */ (packageExports['.']))).toEqual([
|
|
48
|
+
'import',
|
|
49
|
+
'require',
|
|
50
|
+
'default',
|
|
51
|
+
]);
|
|
52
|
+
expect(
|
|
53
|
+
Object.keys(/** @type {Record<string, unknown>} */ (packageExports['./feature'])),
|
|
54
|
+
).toEqual(['import', 'require', 'default']);
|
|
55
|
+
});
|
|
56
|
+
|
|
30
57
|
it('creates exports for a dual bundle module package', async () => {
|
|
31
|
-
await
|
|
58
|
+
const cwd = await makeTempDir();
|
|
59
|
+
const outputDir = path.join(cwd, 'build');
|
|
60
|
+
/**
|
|
61
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
62
|
+
*/
|
|
63
|
+
const bundles = [
|
|
64
|
+
{ type: 'esm', dir: '.' },
|
|
65
|
+
{ type: 'cjs', dir: '.' },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
await Promise.all([
|
|
69
|
+
createFile(path.join(cwd, 'src/index.ts')),
|
|
70
|
+
createFile(path.join(cwd, 'src/feature.ts')),
|
|
71
|
+
|
|
72
|
+
// Create output files for index
|
|
73
|
+
createFile(path.join(outputDir, `index.js`)),
|
|
74
|
+
createFile(path.join(outputDir, `index.cjs`)),
|
|
75
|
+
createFile(path.join(outputDir, `index.d.ts`)),
|
|
76
|
+
createFile(path.join(outputDir, `index.d.cts`)),
|
|
77
|
+
|
|
78
|
+
// Create output files for feature
|
|
79
|
+
createFile(path.join(outputDir, `feature.js`)),
|
|
80
|
+
createFile(path.join(outputDir, `feature.cjs`)),
|
|
81
|
+
createFile(path.join(outputDir, `feature.d.ts`)),
|
|
82
|
+
createFile(path.join(outputDir, `feature.d.cts`)),
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
exports: packageExports,
|
|
87
|
+
main,
|
|
88
|
+
types,
|
|
89
|
+
} = await createPackageExports({
|
|
90
|
+
exports: {
|
|
91
|
+
'.': './src/index.ts',
|
|
92
|
+
'./feature': './src/feature.ts',
|
|
93
|
+
},
|
|
94
|
+
bundles,
|
|
95
|
+
outputDir,
|
|
96
|
+
cwd,
|
|
97
|
+
addTypes: true,
|
|
98
|
+
isFlat: true,
|
|
99
|
+
packageType: 'module',
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(main).toBe('./index.cjs');
|
|
103
|
+
expect(types).toBe('./index.d.cts');
|
|
104
|
+
|
|
105
|
+
expect(packageExports['.']).toEqual({
|
|
106
|
+
import: { types: './index.d.ts', default: './index.js' },
|
|
107
|
+
require: { types: './index.d.cts', default: './index.cjs' },
|
|
108
|
+
default: {
|
|
109
|
+
types: './index.d.ts',
|
|
110
|
+
default: './index.js',
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
expect(packageExports['./feature']).toEqual({
|
|
114
|
+
import: { types: './feature.d.ts', default: './feature.js' },
|
|
115
|
+
require: { types: './feature.d.cts', default: './feature.cjs' },
|
|
116
|
+
default: {
|
|
117
|
+
types: './feature.d.ts',
|
|
118
|
+
default: './feature.js',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
exports: packageExports2,
|
|
124
|
+
main: main2,
|
|
125
|
+
types: types2,
|
|
126
|
+
} = await createPackageExports({
|
|
127
|
+
exports: {
|
|
128
|
+
'.': './src/index.ts',
|
|
129
|
+
'./feature': './src/feature.ts',
|
|
130
|
+
},
|
|
131
|
+
bundles: [bundles[1]], // only CJS bundle
|
|
132
|
+
outputDir,
|
|
133
|
+
cwd,
|
|
134
|
+
addTypes: true,
|
|
135
|
+
isFlat: true,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(main2).toBe('./index.js');
|
|
139
|
+
expect(types2).toBe('./index.d.ts');
|
|
140
|
+
|
|
141
|
+
expect(packageExports2['.']).toEqual({
|
|
142
|
+
require: { types: './index.d.ts', default: './index.js' },
|
|
143
|
+
default: {
|
|
144
|
+
types: './index.d.ts',
|
|
145
|
+
default: './index.js',
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
expect(packageExports2['./feature']).toEqual({
|
|
149
|
+
require: { types: './feature.d.ts', default: './feature.js' },
|
|
150
|
+
default: {
|
|
151
|
+
types: './feature.d.ts',
|
|
152
|
+
default: './feature.js',
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('glob expansion', () => {
|
|
158
|
+
it('expands glob patterns in export keys and values', async () => {
|
|
159
|
+
const cwd = await makeTempDir();
|
|
32
160
|
const outputDir = path.join(cwd, 'build');
|
|
33
161
|
/**
|
|
34
162
|
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
@@ -39,30 +167,23 @@ describe('createPackageExports', () => {
|
|
|
39
167
|
];
|
|
40
168
|
|
|
41
169
|
await Promise.all([
|
|
42
|
-
createFile(path.join(cwd, 'src/
|
|
43
|
-
createFile(path.join(cwd, 'src/
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
createFile(path.join(outputDir,
|
|
47
|
-
createFile(path.join(outputDir,
|
|
48
|
-
createFile(path.join(outputDir,
|
|
49
|
-
createFile(path.join(outputDir,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
createFile(path.join(outputDir,
|
|
53
|
-
createFile(path.join(outputDir,
|
|
54
|
-
createFile(path.join(outputDir, `feature.d.ts`)),
|
|
55
|
-
createFile(path.join(outputDir, `feature.d.cts`)),
|
|
170
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
171
|
+
createFile(path.join(cwd, 'src/TextField.ts')),
|
|
172
|
+
|
|
173
|
+
// Output files
|
|
174
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
175
|
+
createFile(path.join(outputDir, 'Button.cjs')),
|
|
176
|
+
createFile(path.join(outputDir, 'Button.d.ts')),
|
|
177
|
+
createFile(path.join(outputDir, 'Button.d.cts')),
|
|
178
|
+
createFile(path.join(outputDir, 'TextField.js')),
|
|
179
|
+
createFile(path.join(outputDir, 'TextField.cjs')),
|
|
180
|
+
createFile(path.join(outputDir, 'TextField.d.ts')),
|
|
181
|
+
createFile(path.join(outputDir, 'TextField.d.cts')),
|
|
56
182
|
]);
|
|
57
183
|
|
|
58
|
-
const {
|
|
59
|
-
exports: packageExports,
|
|
60
|
-
main,
|
|
61
|
-
types,
|
|
62
|
-
} = await createPackageExports({
|
|
184
|
+
const { exports: packageExports } = await createPackageExports({
|
|
63
185
|
exports: {
|
|
64
|
-
'
|
|
65
|
-
'./feature': './src/feature.ts',
|
|
186
|
+
'./*': './src/*.ts',
|
|
66
187
|
},
|
|
67
188
|
bundles,
|
|
68
189
|
outputDir,
|
|
@@ -72,634 +193,523 @@ describe('createPackageExports', () => {
|
|
|
72
193
|
packageType: 'module',
|
|
73
194
|
});
|
|
74
195
|
|
|
75
|
-
expect(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
import: { types: './index.d.ts', default: './index.js' },
|
|
80
|
-
require: { types: './index.d.cts', default: './index.cjs' },
|
|
81
|
-
default: {
|
|
82
|
-
types: './index.d.ts',
|
|
83
|
-
default: './index.js',
|
|
84
|
-
},
|
|
196
|
+
expect(packageExports['./Button']).toEqual({
|
|
197
|
+
import: { types: './Button.d.ts', default: './Button.js' },
|
|
198
|
+
require: { types: './Button.d.cts', default: './Button.cjs' },
|
|
199
|
+
default: { types: './Button.d.ts', default: './Button.js' },
|
|
85
200
|
});
|
|
86
|
-
expect(packageExports['./
|
|
87
|
-
import: { types: './
|
|
88
|
-
require: { types: './
|
|
89
|
-
default: {
|
|
90
|
-
types: './feature.d.ts',
|
|
91
|
-
default: './feature.js',
|
|
92
|
-
},
|
|
201
|
+
expect(packageExports['./TextField']).toEqual({
|
|
202
|
+
import: { types: './TextField.d.ts', default: './TextField.js' },
|
|
203
|
+
require: { types: './TextField.d.cts', default: './TextField.cjs' },
|
|
204
|
+
default: { types: './TextField.d.ts', default: './TextField.js' },
|
|
93
205
|
});
|
|
206
|
+
// glob key should not appear in the output
|
|
207
|
+
expect(packageExports['./*']).toBeUndefined();
|
|
208
|
+
});
|
|
94
209
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
210
|
+
it('expands glob with commonjs package type', async () => {
|
|
211
|
+
const cwd = await makeTempDir();
|
|
212
|
+
const outputDir = path.join(cwd, 'build');
|
|
213
|
+
/**
|
|
214
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
215
|
+
*/
|
|
216
|
+
const bundles = [
|
|
217
|
+
{ type: 'esm', dir: '.' },
|
|
218
|
+
{ type: 'cjs', dir: '.' },
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
await Promise.all([
|
|
222
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
223
|
+
|
|
224
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
225
|
+
createFile(path.join(outputDir, 'Button.mjs')),
|
|
226
|
+
createFile(path.join(outputDir, 'Button.d.ts')),
|
|
227
|
+
createFile(path.join(outputDir, 'Button.d.mts')),
|
|
228
|
+
]);
|
|
229
|
+
|
|
230
|
+
const { exports: packageExports } = await createPackageExports({
|
|
100
231
|
exports: {
|
|
101
|
-
'
|
|
102
|
-
'./feature': './src/feature.ts',
|
|
232
|
+
'./*': './src/*.ts',
|
|
103
233
|
},
|
|
104
|
-
bundles
|
|
234
|
+
bundles,
|
|
105
235
|
outputDir,
|
|
106
236
|
cwd,
|
|
107
237
|
addTypes: true,
|
|
108
238
|
isFlat: true,
|
|
239
|
+
packageType: 'commonjs',
|
|
109
240
|
});
|
|
110
241
|
|
|
111
|
-
expect(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
require: { types: './index.d.ts', default: './index.js' },
|
|
116
|
-
default: {
|
|
117
|
-
types: './index.d.ts',
|
|
118
|
-
default: './index.js',
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
expect(packageExports2['./feature']).toEqual({
|
|
122
|
-
require: { types: './feature.d.ts', default: './feature.js' },
|
|
123
|
-
default: {
|
|
124
|
-
types: './feature.d.ts',
|
|
125
|
-
default: './feature.js',
|
|
126
|
-
},
|
|
242
|
+
expect(packageExports['./Button']).toEqual({
|
|
243
|
+
import: { types: './Button.d.mts', default: './Button.mjs' },
|
|
244
|
+
require: { types: './Button.d.ts', default: './Button.js' },
|
|
245
|
+
default: { types: './Button.d.mts', default: './Button.mjs' },
|
|
127
246
|
});
|
|
128
247
|
});
|
|
129
|
-
});
|
|
130
248
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const outputDir = path.join(cwd, 'build');
|
|
135
|
-
/**
|
|
136
|
-
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
137
|
-
*/
|
|
138
|
-
const bundles = [
|
|
139
|
-
{ type: 'esm', dir: '.' },
|
|
140
|
-
{ type: 'cjs', dir: '.' },
|
|
141
|
-
];
|
|
142
|
-
|
|
143
|
-
await Promise.all([
|
|
144
|
-
createFile(path.join(cwd, 'src/Button.ts')),
|
|
145
|
-
createFile(path.join(cwd, 'src/TextField.ts')),
|
|
146
|
-
|
|
147
|
-
// Output files
|
|
148
|
-
createFile(path.join(outputDir, 'Button.js')),
|
|
149
|
-
createFile(path.join(outputDir, 'Button.cjs')),
|
|
150
|
-
createFile(path.join(outputDir, 'Button.d.ts')),
|
|
151
|
-
createFile(path.join(outputDir, 'Button.d.cts')),
|
|
152
|
-
createFile(path.join(outputDir, 'TextField.js')),
|
|
153
|
-
createFile(path.join(outputDir, 'TextField.cjs')),
|
|
154
|
-
createFile(path.join(outputDir, 'TextField.d.ts')),
|
|
155
|
-
createFile(path.join(outputDir, 'TextField.d.cts')),
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
const { exports: packageExports } = await createPackageExports({
|
|
159
|
-
exports: {
|
|
160
|
-
'./*': './src/*.ts',
|
|
161
|
-
},
|
|
162
|
-
bundles,
|
|
163
|
-
outputDir,
|
|
164
|
-
cwd,
|
|
165
|
-
addTypes: true,
|
|
166
|
-
isFlat: true,
|
|
167
|
-
packageType: 'module',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
expect(packageExports['./Button']).toEqual({
|
|
171
|
-
import: { types: './Button.d.ts', default: './Button.js' },
|
|
172
|
-
require: { types: './Button.d.cts', default: './Button.cjs' },
|
|
173
|
-
default: { types: './Button.d.ts', default: './Button.js' },
|
|
174
|
-
});
|
|
175
|
-
expect(packageExports['./TextField']).toEqual({
|
|
176
|
-
import: { types: './TextField.d.ts', default: './TextField.js' },
|
|
177
|
-
require: { types: './TextField.d.cts', default: './TextField.cjs' },
|
|
178
|
-
default: { types: './TextField.d.ts', default: './TextField.js' },
|
|
179
|
-
});
|
|
180
|
-
// glob key should not appear in the output
|
|
181
|
-
expect(packageExports['./*']).toBeUndefined();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
249
|
+
it('expands glob with single CJS bundle', async () => {
|
|
250
|
+
const cwd = await makeTempDir();
|
|
251
|
+
const outputDir = path.join(cwd, 'build');
|
|
184
252
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
createFile(path.join(outputDir, 'Button.d.mts')),
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
const { exports: packageExports } = await createPackageExports({
|
|
206
|
-
exports: {
|
|
207
|
-
'./*': './src/*.ts',
|
|
208
|
-
},
|
|
209
|
-
bundles,
|
|
210
|
-
outputDir,
|
|
211
|
-
cwd,
|
|
212
|
-
addTypes: true,
|
|
213
|
-
isFlat: true,
|
|
214
|
-
packageType: 'commonjs',
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
expect(packageExports['./Button']).toEqual({
|
|
218
|
-
import: { types: './Button.d.mts', default: './Button.mjs' },
|
|
219
|
-
require: { types: './Button.d.ts', default: './Button.js' },
|
|
220
|
-
default: { types: './Button.d.mts', default: './Button.mjs' },
|
|
221
|
-
});
|
|
253
|
+
await Promise.all([
|
|
254
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
255
|
+
|
|
256
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
257
|
+
createFile(path.join(outputDir, 'Button.d.ts')),
|
|
258
|
+
]);
|
|
259
|
+
|
|
260
|
+
const { exports: packageExports } = await createPackageExports({
|
|
261
|
+
exports: {
|
|
262
|
+
'./*': './src/*.ts',
|
|
263
|
+
},
|
|
264
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
265
|
+
outputDir,
|
|
266
|
+
cwd,
|
|
267
|
+
addTypes: true,
|
|
268
|
+
isFlat: true,
|
|
269
|
+
packageType: 'commonjs',
|
|
222
270
|
});
|
|
223
|
-
});
|
|
224
271
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
await Promise.all([
|
|
230
|
-
createFile(path.join(cwd, 'src/Button.ts')),
|
|
231
|
-
|
|
232
|
-
createFile(path.join(outputDir, 'Button.js')),
|
|
233
|
-
createFile(path.join(outputDir, 'Button.d.ts')),
|
|
234
|
-
]);
|
|
235
|
-
|
|
236
|
-
const { exports: packageExports } = await createPackageExports({
|
|
237
|
-
exports: {
|
|
238
|
-
'./*': './src/*.ts',
|
|
239
|
-
},
|
|
240
|
-
bundles: [{ type: 'cjs', dir: '.' }],
|
|
241
|
-
outputDir,
|
|
242
|
-
cwd,
|
|
243
|
-
addTypes: true,
|
|
244
|
-
isFlat: true,
|
|
245
|
-
packageType: 'commonjs',
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
expect(packageExports['./Button']).toEqual({
|
|
249
|
-
require: { types: './Button.d.ts', default: './Button.js' },
|
|
250
|
-
default: { types: './Button.d.ts', default: './Button.js' },
|
|
251
|
-
});
|
|
272
|
+
expect(packageExports['./Button']).toEqual({
|
|
273
|
+
require: { types: './Button.d.ts', default: './Button.js' },
|
|
274
|
+
default: { types: './Button.d.ts', default: './Button.js' },
|
|
252
275
|
});
|
|
253
276
|
});
|
|
254
277
|
|
|
255
278
|
it('expands glob patterns with mui-src object values', async () => {
|
|
256
|
-
await
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
});
|
|
279
|
+
const cwd = await makeTempDir();
|
|
280
|
+
const outputDir = path.join(cwd, 'build');
|
|
281
|
+
/**
|
|
282
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
283
|
+
*/
|
|
284
|
+
const bundles = [
|
|
285
|
+
{ type: 'esm', dir: '.' },
|
|
286
|
+
{ type: 'cjs', dir: '.' },
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
await Promise.all([
|
|
290
|
+
createFile(path.join(cwd, 'src/Alert.ts')),
|
|
291
|
+
|
|
292
|
+
createFile(path.join(outputDir, 'Alert.js')),
|
|
293
|
+
createFile(path.join(outputDir, 'Alert.cjs')),
|
|
294
|
+
]);
|
|
295
|
+
|
|
296
|
+
const { exports: packageExports } = await createPackageExports({
|
|
297
|
+
exports: {
|
|
298
|
+
'./*': { 'mui-src': './src/*.ts' },
|
|
299
|
+
},
|
|
300
|
+
bundles,
|
|
301
|
+
outputDir,
|
|
302
|
+
cwd,
|
|
303
|
+
isFlat: true,
|
|
304
|
+
packageType: 'module',
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(packageExports['./Alert']).toEqual({
|
|
308
|
+
import: './Alert.js',
|
|
309
|
+
require: './Alert.cjs',
|
|
310
|
+
default: './Alert.js',
|
|
289
311
|
});
|
|
290
312
|
});
|
|
291
313
|
|
|
292
314
|
it('preserves extra conditions from mui-src object values', async () => {
|
|
293
|
-
await
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
});
|
|
315
|
+
const cwd = await makeTempDir();
|
|
316
|
+
const outputDir = path.join(cwd, 'build');
|
|
317
|
+
/**
|
|
318
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
319
|
+
*/
|
|
320
|
+
const bundles = [
|
|
321
|
+
{ type: 'esm', dir: '.' },
|
|
322
|
+
{ type: 'cjs', dir: '.' },
|
|
323
|
+
];
|
|
324
|
+
|
|
325
|
+
await Promise.all([
|
|
326
|
+
createFile(path.join(cwd, 'src/Alert.ts')),
|
|
327
|
+
|
|
328
|
+
createFile(path.join(outputDir, 'Alert.js')),
|
|
329
|
+
createFile(path.join(outputDir, 'Alert.cjs')),
|
|
330
|
+
]);
|
|
331
|
+
|
|
332
|
+
const { exports: packageExports } = await createPackageExports({
|
|
333
|
+
exports: {
|
|
334
|
+
'./*': { 'mui-src': './src/*.ts', node: './src/node/*.ts' },
|
|
335
|
+
},
|
|
336
|
+
bundles,
|
|
337
|
+
outputDir,
|
|
338
|
+
cwd,
|
|
339
|
+
isFlat: true,
|
|
340
|
+
packageType: 'module',
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
expect(packageExports['./Alert']).toEqual({
|
|
344
|
+
import: { node: './src/node/*.ts', default: './Alert.js' },
|
|
345
|
+
require: { node: './src/node/*.ts', default: './Alert.cjs' },
|
|
346
|
+
default: './Alert.js',
|
|
326
347
|
});
|
|
327
348
|
});
|
|
328
349
|
|
|
329
350
|
it('mixes glob and non-glob exports', async () => {
|
|
330
|
-
await
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
351
|
+
const cwd = await makeTempDir();
|
|
352
|
+
const outputDir = path.join(cwd, 'build');
|
|
353
|
+
/**
|
|
354
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
355
|
+
*/
|
|
356
|
+
const bundles = [
|
|
357
|
+
{ type: 'esm', dir: '.' },
|
|
358
|
+
{ type: 'cjs', dir: '.' },
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
await Promise.all([
|
|
362
|
+
createFile(path.join(cwd, 'src/index.ts')),
|
|
363
|
+
createFile(path.join(cwd, 'src/Chip.ts')),
|
|
364
|
+
|
|
365
|
+
createFile(path.join(outputDir, 'index.js')),
|
|
366
|
+
createFile(path.join(outputDir, 'index.cjs')),
|
|
367
|
+
createFile(path.join(outputDir, 'Chip.js')),
|
|
368
|
+
createFile(path.join(outputDir, 'Chip.cjs')),
|
|
369
|
+
]);
|
|
370
|
+
|
|
371
|
+
const { exports: packageExports } = await createPackageExports({
|
|
372
|
+
exports: {
|
|
373
|
+
'.': './src/index.ts',
|
|
374
|
+
'./*': './src/*.ts',
|
|
375
|
+
},
|
|
376
|
+
bundles,
|
|
377
|
+
outputDir,
|
|
378
|
+
cwd,
|
|
379
|
+
isFlat: true,
|
|
380
|
+
packageType: 'module',
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Explicit export still works
|
|
384
|
+
expect(packageExports['.']).toBeDefined();
|
|
385
|
+
// Glob-expanded export
|
|
386
|
+
expect(packageExports['./Chip']).toEqual({
|
|
387
|
+
import: './Chip.js',
|
|
388
|
+
require: './Chip.cjs',
|
|
389
|
+
default: './Chip.js',
|
|
370
390
|
});
|
|
371
391
|
});
|
|
372
392
|
|
|
373
393
|
it('expands glob with subdirectory pattern', async () => {
|
|
374
|
-
await
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
});
|
|
394
|
+
const cwd = await makeTempDir();
|
|
395
|
+
const outputDir = path.join(cwd, 'build');
|
|
396
|
+
/**
|
|
397
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
398
|
+
*/
|
|
399
|
+
const bundles = [
|
|
400
|
+
{ type: 'esm', dir: '.' },
|
|
401
|
+
{ type: 'cjs', dir: '.' },
|
|
402
|
+
];
|
|
403
|
+
|
|
404
|
+
await Promise.all([
|
|
405
|
+
createFile(path.join(cwd, 'src/utils/color.ts')),
|
|
406
|
+
createFile(path.join(cwd, 'src/utils/size.ts')),
|
|
407
|
+
|
|
408
|
+
createFile(path.join(outputDir, 'utils/color.js')),
|
|
409
|
+
createFile(path.join(outputDir, 'utils/color.cjs')),
|
|
410
|
+
createFile(path.join(outputDir, 'utils/size.js')),
|
|
411
|
+
createFile(path.join(outputDir, 'utils/size.cjs')),
|
|
412
|
+
]);
|
|
413
|
+
|
|
414
|
+
const { exports: packageExports } = await createPackageExports({
|
|
415
|
+
exports: {
|
|
416
|
+
'./utils/*': './src/utils/*.ts',
|
|
417
|
+
},
|
|
418
|
+
bundles,
|
|
419
|
+
outputDir,
|
|
420
|
+
cwd,
|
|
421
|
+
isFlat: true,
|
|
422
|
+
packageType: 'module',
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
expect(packageExports['./utils/color']).toEqual({
|
|
426
|
+
import: './utils/color.js',
|
|
427
|
+
require: './utils/color.cjs',
|
|
428
|
+
default: './utils/color.js',
|
|
429
|
+
});
|
|
430
|
+
expect(packageExports['./utils/size']).toEqual({
|
|
431
|
+
import: './utils/size.js',
|
|
432
|
+
require: './utils/size.cjs',
|
|
433
|
+
default: './utils/size.js',
|
|
415
434
|
});
|
|
416
435
|
});
|
|
417
436
|
|
|
418
437
|
it('produces no entries when glob matches nothing', async () => {
|
|
419
|
-
await
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
// Only the default ./package.json entry should be present
|
|
436
|
-
expect(Object.keys(packageExports)).toEqual(['./package.json']);
|
|
438
|
+
const cwd = await makeTempDir();
|
|
439
|
+
const outputDir = path.join(cwd, 'build');
|
|
440
|
+
|
|
441
|
+
// Create the src directory but no .ts files in it
|
|
442
|
+
createFile(path.join(cwd, 'src/.gitkeep'));
|
|
443
|
+
|
|
444
|
+
const { exports: packageExports } = await createPackageExports({
|
|
445
|
+
exports: {
|
|
446
|
+
'./*': './src/*.ts',
|
|
447
|
+
},
|
|
448
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
449
|
+
outputDir,
|
|
450
|
+
cwd,
|
|
451
|
+
isFlat: true,
|
|
437
452
|
});
|
|
453
|
+
|
|
454
|
+
// Only the default ./package.json entry should be present
|
|
455
|
+
expect(Object.keys(packageExports)).toEqual(['./package.json']);
|
|
438
456
|
});
|
|
439
457
|
|
|
440
458
|
it('expands globs in sorted order', async () => {
|
|
441
|
-
await
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
const exportKeys = Object.keys(packageExports).filter((k) => k !== './package.json');
|
|
465
|
-
expect(exportKeys).toEqual(['./Apple', './Mango', './Zebra']);
|
|
459
|
+
const cwd = await makeTempDir();
|
|
460
|
+
const outputDir = path.join(cwd, 'build');
|
|
461
|
+
|
|
462
|
+
await Promise.all([
|
|
463
|
+
createFile(path.join(cwd, 'src/Zebra.ts')),
|
|
464
|
+
createFile(path.join(cwd, 'src/Apple.ts')),
|
|
465
|
+
createFile(path.join(cwd, 'src/Mango.ts')),
|
|
466
|
+
|
|
467
|
+
createFile(path.join(outputDir, 'Zebra.js')),
|
|
468
|
+
createFile(path.join(outputDir, 'Apple.js')),
|
|
469
|
+
createFile(path.join(outputDir, 'Mango.js')),
|
|
470
|
+
]);
|
|
471
|
+
|
|
472
|
+
const { exports: packageExports } = await createPackageExports({
|
|
473
|
+
exports: {
|
|
474
|
+
'./*': './src/*.ts',
|
|
475
|
+
},
|
|
476
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
477
|
+
outputDir,
|
|
478
|
+
cwd,
|
|
479
|
+
isFlat: true,
|
|
466
480
|
});
|
|
481
|
+
|
|
482
|
+
const exportKeys = Object.keys(packageExports).filter((k) => k !== './package.json');
|
|
483
|
+
expect(exportKeys).toEqual(['./Apple', './Mango', './Zebra']);
|
|
467
484
|
});
|
|
468
485
|
|
|
469
486
|
it('removes expanded entries matching a null-valued glob (negation)', async () => {
|
|
470
|
-
await
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
expect(packageExports['./Accordion']).toBeDefined();
|
|
506
|
-
expect(packageExports['./Button']).toBeUndefined();
|
|
507
|
-
expect(packageExports['./ButtonBase']).toBeUndefined();
|
|
508
|
-
// The negation glob key itself should not appear
|
|
509
|
-
expect(packageExports['./Button*']).toBeUndefined();
|
|
487
|
+
const cwd = await makeTempDir();
|
|
488
|
+
const outputDir = path.join(cwd, 'build');
|
|
489
|
+
/**
|
|
490
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
491
|
+
*/
|
|
492
|
+
const bundles = [
|
|
493
|
+
{ type: 'esm', dir: '.' },
|
|
494
|
+
{ type: 'cjs', dir: '.' },
|
|
495
|
+
];
|
|
496
|
+
|
|
497
|
+
await Promise.all([
|
|
498
|
+
createFile(path.join(cwd, 'src/Accordion.ts')),
|
|
499
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
500
|
+
createFile(path.join(cwd, 'src/ButtonBase.ts')),
|
|
501
|
+
|
|
502
|
+
createFile(path.join(outputDir, 'Accordion.js')),
|
|
503
|
+
createFile(path.join(outputDir, 'Accordion.cjs')),
|
|
504
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
505
|
+
createFile(path.join(outputDir, 'Button.cjs')),
|
|
506
|
+
createFile(path.join(outputDir, 'ButtonBase.js')),
|
|
507
|
+
createFile(path.join(outputDir, 'ButtonBase.cjs')),
|
|
508
|
+
]);
|
|
509
|
+
|
|
510
|
+
const { exports: packageExports } = await createPackageExports({
|
|
511
|
+
exports: {
|
|
512
|
+
'./*': './src/*.ts',
|
|
513
|
+
'./Button*': null,
|
|
514
|
+
},
|
|
515
|
+
bundles,
|
|
516
|
+
outputDir,
|
|
517
|
+
cwd,
|
|
518
|
+
isFlat: true,
|
|
519
|
+
packageType: 'module',
|
|
510
520
|
});
|
|
521
|
+
|
|
522
|
+
expect(packageExports['./Accordion']).toBeDefined();
|
|
523
|
+
expect(packageExports['./Button']).toBeUndefined();
|
|
524
|
+
expect(packageExports['./ButtonBase']).toBeUndefined();
|
|
525
|
+
// The negation glob key itself should not appear
|
|
526
|
+
expect(packageExports['./Button*']).toBeUndefined();
|
|
511
527
|
});
|
|
512
528
|
|
|
513
529
|
it('negation with null removes only matching keys', async () => {
|
|
514
|
-
await
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
const exportKeys = Object.keys(packageExports).filter((k) => k !== './package.json');
|
|
539
|
-
expect(exportKeys).toEqual(['./Button']);
|
|
530
|
+
const cwd = await makeTempDir();
|
|
531
|
+
const outputDir = path.join(cwd, 'build');
|
|
532
|
+
|
|
533
|
+
await Promise.all([
|
|
534
|
+
createFile(path.join(cwd, 'src/Alert.ts')),
|
|
535
|
+
createFile(path.join(cwd, 'src/AlertTitle.ts')),
|
|
536
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
537
|
+
|
|
538
|
+
createFile(path.join(outputDir, 'Alert.js')),
|
|
539
|
+
createFile(path.join(outputDir, 'AlertTitle.js')),
|
|
540
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
541
|
+
]);
|
|
542
|
+
|
|
543
|
+
const { exports: packageExports } = await createPackageExports({
|
|
544
|
+
exports: {
|
|
545
|
+
'./*': './src/*.ts',
|
|
546
|
+
'./Alert*': null,
|
|
547
|
+
},
|
|
548
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
549
|
+
outputDir,
|
|
550
|
+
cwd,
|
|
551
|
+
isFlat: true,
|
|
540
552
|
});
|
|
553
|
+
|
|
554
|
+
const exportKeys = Object.keys(packageExports).filter((k) => k !== './package.json');
|
|
555
|
+
expect(exportKeys).toEqual(['./Button']);
|
|
541
556
|
});
|
|
542
557
|
|
|
543
558
|
it('preserves null glob pattern when no keys match', async () => {
|
|
544
|
-
await
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
// Button is kept since it doesn't match the negation
|
|
564
|
-
expect(packageExports['./Button']).toBeDefined();
|
|
565
|
-
// The negation pattern is preserved as null since nothing matched it
|
|
566
|
-
expect(packageExports['./internal/*']).toBeNull();
|
|
559
|
+
const cwd = await makeTempDir();
|
|
560
|
+
const outputDir = path.join(cwd, 'build');
|
|
561
|
+
|
|
562
|
+
await Promise.all([
|
|
563
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
564
|
+
createFile(path.join(outputDir, 'Button.js')),
|
|
565
|
+
]);
|
|
566
|
+
|
|
567
|
+
const { exports: packageExports } = await createPackageExports({
|
|
568
|
+
exports: {
|
|
569
|
+
'./*': './src/*.ts',
|
|
570
|
+
'./internal/*': null,
|
|
571
|
+
},
|
|
572
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
573
|
+
outputDir,
|
|
574
|
+
cwd,
|
|
575
|
+
isFlat: true,
|
|
567
576
|
});
|
|
577
|
+
|
|
578
|
+
// Button is kept since it doesn't match the negation
|
|
579
|
+
expect(packageExports['./Button']).toBeDefined();
|
|
580
|
+
// The negation pattern is preserved as null since nothing matched it
|
|
581
|
+
expect(packageExports['./internal/*']).toBeNull();
|
|
568
582
|
});
|
|
569
583
|
|
|
570
584
|
it('does not expand glob patterns when isFlat is false', async () => {
|
|
571
|
-
await
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
// Glob should NOT be expanded to individual files
|
|
590
|
-
expect(packageExports['./Button']).toBeUndefined();
|
|
591
|
-
expect(packageExports['./TextField']).toBeUndefined();
|
|
592
|
-
// The raw glob pattern is passed through as-is
|
|
593
|
-
expect(packageExports['./*']).toEqual({
|
|
594
|
-
require: './*.js',
|
|
595
|
-
default: './*.js',
|
|
596
|
-
});
|
|
585
|
+
const cwd = await makeTempDir();
|
|
586
|
+
const outputDir = path.join(cwd, 'build');
|
|
587
|
+
|
|
588
|
+
await Promise.all([
|
|
589
|
+
createFile(path.join(cwd, 'src/Button.ts')),
|
|
590
|
+
createFile(path.join(cwd, 'src/TextField.ts')),
|
|
591
|
+
]);
|
|
592
|
+
|
|
593
|
+
const { exports: packageExports } = await createPackageExports({
|
|
594
|
+
exports: {
|
|
595
|
+
'./*': './src/*.ts',
|
|
596
|
+
},
|
|
597
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
598
|
+
outputDir,
|
|
599
|
+
cwd,
|
|
600
|
+
isFlat: false,
|
|
597
601
|
});
|
|
598
|
-
});
|
|
599
602
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
]);
|
|
608
|
-
|
|
609
|
-
const { exports: packageExports } = await createPackageExports({
|
|
610
|
-
exports: {
|
|
611
|
-
'./*': './src/index.ts',
|
|
612
|
-
},
|
|
613
|
-
bundles: [{ type: 'cjs', dir: '.' }],
|
|
614
|
-
outputDir,
|
|
615
|
-
cwd,
|
|
616
|
-
isFlat: true,
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
// When the value has no *, the glob key is passed through as-is
|
|
620
|
-
expect(packageExports['./*']).toBeDefined();
|
|
603
|
+
// Glob should NOT be expanded to individual files
|
|
604
|
+
expect(packageExports['./Button']).toBeUndefined();
|
|
605
|
+
expect(packageExports['./TextField']).toBeUndefined();
|
|
606
|
+
// The raw glob pattern is passed through as-is
|
|
607
|
+
expect(packageExports['./*']).toEqual({
|
|
608
|
+
require: './*.js',
|
|
609
|
+
default: './*.js',
|
|
621
610
|
});
|
|
622
611
|
});
|
|
623
|
-
});
|
|
624
612
|
|
|
625
|
-
|
|
626
|
-
|
|
613
|
+
it('passes through glob key when value has no wildcard', async () => {
|
|
614
|
+
const cwd = await makeTempDir();
|
|
627
615
|
const outputDir = path.join(cwd, 'build');
|
|
628
616
|
|
|
629
617
|
await Promise.all([
|
|
630
618
|
createFile(path.join(cwd, 'src/index.ts')),
|
|
631
619
|
createFile(path.join(outputDir, 'index.js')),
|
|
632
|
-
createFile(path.join(outputDir, 'index.d.ts')),
|
|
633
620
|
]);
|
|
634
621
|
|
|
635
622
|
const { exports: packageExports } = await createPackageExports({
|
|
636
623
|
exports: {
|
|
637
|
-
'
|
|
624
|
+
'./*': './src/index.ts',
|
|
638
625
|
},
|
|
639
626
|
bundles: [{ type: 'cjs', dir: '.' }],
|
|
640
627
|
outputDir,
|
|
641
628
|
cwd,
|
|
642
|
-
addTypes: true,
|
|
643
629
|
isFlat: true,
|
|
644
|
-
packageType: 'commonjs',
|
|
645
630
|
});
|
|
646
631
|
|
|
647
|
-
//
|
|
648
|
-
expect(packageExports['
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
632
|
+
// When the value has no *, the glob key is passed through as-is
|
|
633
|
+
expect(packageExports['./*']).toBeDefined();
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it('uses require/import and default for single bundle package', async () => {
|
|
638
|
+
const cwd = await makeTempDir();
|
|
639
|
+
const outputDir = path.join(cwd, 'build');
|
|
640
|
+
|
|
641
|
+
await Promise.all([
|
|
642
|
+
createFile(path.join(cwd, 'src/index.ts')),
|
|
643
|
+
createFile(path.join(outputDir, 'index.js')),
|
|
644
|
+
createFile(path.join(outputDir, 'index.d.ts')),
|
|
645
|
+
]);
|
|
646
|
+
|
|
647
|
+
const { exports: packageExports } = await createPackageExports({
|
|
648
|
+
exports: {
|
|
649
|
+
'.': './src/index.ts',
|
|
650
|
+
},
|
|
651
|
+
bundles: [{ type: 'cjs', dir: '.' }],
|
|
652
|
+
outputDir,
|
|
653
|
+
cwd,
|
|
654
|
+
addTypes: true,
|
|
655
|
+
isFlat: true,
|
|
656
|
+
packageType: 'commonjs',
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
// Single CJS bundle should have both require and default pointing to the same files
|
|
660
|
+
expect(packageExports['.']).toEqual({
|
|
661
|
+
require: {
|
|
662
|
+
types: './index.d.ts',
|
|
663
|
+
default: './index.js',
|
|
664
|
+
},
|
|
665
|
+
default: {
|
|
666
|
+
types: './index.d.ts',
|
|
667
|
+
default: './index.js',
|
|
668
|
+
},
|
|
658
669
|
});
|
|
659
670
|
});
|
|
660
671
|
});
|
|
661
672
|
|
|
662
673
|
describe('createPackageBin', () => {
|
|
663
674
|
it('prefers the ESM bundle when available', async () => {
|
|
664
|
-
await
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
expect(bin).toBe('./cli.js');
|
|
675
|
+
const cwd = await makeTempDir();
|
|
676
|
+
/**
|
|
677
|
+
* @type {{ type: import('./build.mjs').BundleType; dir: string }[]}
|
|
678
|
+
*/
|
|
679
|
+
const bundles = [
|
|
680
|
+
{ type: 'esm', dir: '.' },
|
|
681
|
+
{ type: 'cjs', dir: '.' },
|
|
682
|
+
];
|
|
683
|
+
|
|
684
|
+
await Promise.all([createFile(path.join(cwd, 'src/cli.ts'))]);
|
|
685
|
+
|
|
686
|
+
let bin = await createPackageBin({
|
|
687
|
+
bin: './src/cli.ts',
|
|
688
|
+
bundles,
|
|
689
|
+
cwd,
|
|
690
|
+
isFlat: true,
|
|
691
|
+
packageType: 'module',
|
|
692
|
+
});
|
|
684
693
|
|
|
685
|
-
|
|
686
|
-
bin: './src/cli.ts',
|
|
687
|
-
bundles: [bundles[1]], // only CJS bundle
|
|
688
|
-
cwd,
|
|
689
|
-
isFlat: true,
|
|
690
|
-
});
|
|
694
|
+
expect(bin).toBe('./cli.js');
|
|
691
695
|
|
|
692
|
-
|
|
696
|
+
bin = await createPackageBin({
|
|
697
|
+
bin: './src/cli.ts',
|
|
698
|
+
bundles: [bundles[1]], // only CJS bundle
|
|
699
|
+
cwd,
|
|
700
|
+
isFlat: true,
|
|
701
|
+
});
|
|
693
702
|
|
|
694
|
-
|
|
695
|
-
bin: './src/cli.ts',
|
|
696
|
-
bundles, // only CJS bundle
|
|
697
|
-
cwd,
|
|
698
|
-
isFlat: true,
|
|
699
|
-
packageType: 'commonjs',
|
|
700
|
-
});
|
|
703
|
+
expect(bin).toBe('./cli.js');
|
|
701
704
|
|
|
702
|
-
|
|
705
|
+
bin = await createPackageBin({
|
|
706
|
+
bin: './src/cli.ts',
|
|
707
|
+
bundles, // only CJS bundle
|
|
708
|
+
cwd,
|
|
709
|
+
isFlat: true,
|
|
710
|
+
packageType: 'commonjs',
|
|
703
711
|
});
|
|
712
|
+
|
|
713
|
+
expect(bin).toBe('./cli.mjs');
|
|
704
714
|
});
|
|
705
715
|
});
|