@nx/js 0.0.0-pr-3-4212ebd → 0.0.0-pr-30457-3ca7e98
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/package.json +3 -5
- package/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +2 -1
- package/src/generators/library/library.js +5 -12
- package/src/generators/setup-build/generator.js +4 -0
- package/src/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/plugin.js +53 -3
- package/src/plugins/typescript/util.js +2 -3
- package/src/utils/buildable-libs-utils.d.ts +0 -2
- package/src/utils/buildable-libs-utils.js +1 -33
- package/src/utils/package-json/update-package-json.d.ts +1 -0
- package/src/utils/package-json/update-package-json.js +42 -1
- package/src/utils/typescript/tsnode-register.d.ts +0 -1
- package/src/utils/typescript/tsnode-register.js +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-30457-3ca7e98",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "0.0.0-pr-
|
|
43
|
-
"@nx/workspace": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-30457-3ca7e98",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-30457-3ca7e98",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -60,8 +60,6 @@
|
|
|
60
60
|
"semver": "^7.5.3",
|
|
61
61
|
"source-map-support": "0.5.19",
|
|
62
62
|
"tinyglobby": "^0.2.12",
|
|
63
|
-
"ts-node": "10.9.1",
|
|
64
|
-
"tsconfig-paths": "^4.1.2",
|
|
65
63
|
"tslib": "^2.3.0"
|
|
66
64
|
},
|
|
67
65
|
"peerDependencies": {
|
|
@@ -425,6 +425,8 @@ function createFiles(tree, options) {
|
|
|
425
425
|
};
|
|
426
426
|
if (options.isUsingTsSolutionConfig &&
|
|
427
427
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
428
|
+
// the file must exist in the TS solution setup
|
|
429
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
428
430
|
return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
|
|
429
431
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
430
432
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -433,6 +435,7 @@ function createFiles(tree, options) {
|
|
|
433
435
|
generateExportsField: true,
|
|
434
436
|
packageJsonPath,
|
|
435
437
|
format: ['esm'],
|
|
438
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
436
439
|
});
|
|
437
440
|
}
|
|
438
441
|
return updatedPackageJson;
|
|
@@ -455,6 +458,7 @@ function createFiles(tree, options) {
|
|
|
455
458
|
}
|
|
456
459
|
if (options.isUsingTsSolutionConfig &&
|
|
457
460
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
461
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
458
462
|
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
459
463
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
460
464
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -463,6 +467,7 @@ function createFiles(tree, options) {
|
|
|
463
467
|
generateExportsField: true,
|
|
464
468
|
packageJsonPath,
|
|
465
469
|
format: ['esm'],
|
|
470
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
466
471
|
});
|
|
467
472
|
}
|
|
468
473
|
if (!options.useProjectJson && options.name !== options.importPath) {
|
|
@@ -732,12 +737,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
732
737
|
json.references.push({
|
|
733
738
|
path: './tsconfig.lib.json',
|
|
734
739
|
});
|
|
735
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
736
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
737
|
-
if (options.bundler === 'tsc') {
|
|
738
|
-
json['nx'] ??= {};
|
|
739
|
-
json['nx'].addTypecheckTarget = false;
|
|
740
|
-
}
|
|
741
740
|
return json;
|
|
742
741
|
});
|
|
743
742
|
}
|
|
@@ -749,12 +748,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
749
748
|
include: [],
|
|
750
749
|
references: [{ path: './tsconfig.lib.json' }],
|
|
751
750
|
};
|
|
752
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
753
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
754
|
-
if (options.bundler === 'tsc') {
|
|
755
|
-
tsconfig['nx'] ??= {};
|
|
756
|
-
tsconfig['nx'].addTypecheckTarget = false;
|
|
757
|
-
}
|
|
758
751
|
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
759
752
|
// update root project tsconfig.json references with the new lib tsconfig
|
|
760
753
|
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
@@ -232,6 +232,9 @@ function updatePackageJson(tree, projectName, projectRoot, main, outputPath, roo
|
|
|
232
232
|
version: '0.0.1',
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
+
// the file must exist in the TS solution setup, which is the only case this
|
|
236
|
+
// function is called
|
|
237
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
235
238
|
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
236
239
|
main,
|
|
237
240
|
outputPath,
|
|
@@ -240,6 +243,7 @@ function updatePackageJson(tree, projectName, projectRoot, main, outputPath, roo
|
|
|
240
243
|
packageJsonPath,
|
|
241
244
|
rootDir,
|
|
242
245
|
format,
|
|
246
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
243
247
|
});
|
|
244
248
|
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
245
249
|
}
|
|
@@ -29,17 +29,21 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
|
|
|
29
29
|
const port = parseInt(data.toString().match(new RegExp(`${listenAddress}:(?<port>\\d+)`))
|
|
30
30
|
?.groups?.port);
|
|
31
31
|
const registry = `http://${listenAddress}:${port}`;
|
|
32
|
+
const authToken = 'secretVerdaccioToken';
|
|
32
33
|
console.log(`Local registry started on ${registry}`);
|
|
33
34
|
process.env.npm_config_registry = registry;
|
|
34
|
-
(0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "
|
|
35
|
+
(0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "${authToken}" --ws=false`, {
|
|
35
36
|
windowsHide: false,
|
|
36
37
|
});
|
|
38
|
+
// bun
|
|
39
|
+
process.env.BUN_CONFIG_REGISTRY = registry;
|
|
40
|
+
process.env.BUN_CONFIG_TOKEN = authToken;
|
|
37
41
|
// yarnv1
|
|
38
42
|
process.env.YARN_REGISTRY = registry;
|
|
39
43
|
// yarnv2
|
|
40
44
|
process.env.YARN_NPM_REGISTRY_SERVER = registry;
|
|
41
45
|
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;
|
|
42
|
-
console.log('Set npm and yarn config registry to ' + registry);
|
|
46
|
+
console.log('Set npm, bun, and yarn config registry to ' + registry);
|
|
43
47
|
resolve(() => {
|
|
44
48
|
childProcess.kill();
|
|
45
49
|
(0, child_process_1.execSync)(`npm config delete //${listenAddress}:${port}/:_authToken --ws=false`, {
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createNodes = exports.createNodesV2 = exports.PLUGIN_NAME = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
6
|
-
const picomatch = require("picomatch");
|
|
7
6
|
const node_fs_1 = require("node:fs");
|
|
8
7
|
const node_path_1 = require("node:path");
|
|
9
8
|
const posix = require("node:path/posix");
|
|
10
9
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
10
|
+
const picomatch = require("picomatch");
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
12
12
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
13
13
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
14
14
|
const util_1 = require("./util");
|
|
15
|
+
let ts;
|
|
15
16
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
17
|
let tsConfigCache;
|
|
17
18
|
const tsConfigCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
|
|
@@ -144,6 +145,9 @@ async function getConfigFileHash(configFilePath, workspaceRoot, projectRoot, opt
|
|
|
144
145
|
lockFileHash,
|
|
145
146
|
optionsHash,
|
|
146
147
|
...(packageJson ? [(0, file_hasher_1.hashObject)(packageJson)] : []),
|
|
148
|
+
// change this to bust the cache when making changes that would yield
|
|
149
|
+
// different results for the same hash
|
|
150
|
+
(0, file_hasher_1.hashObject)({ bust: 1 }),
|
|
147
151
|
]);
|
|
148
152
|
}
|
|
149
153
|
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, context) {
|
|
@@ -260,10 +264,57 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
260
264
|
...Object.entries(internalProjectReferences),
|
|
261
265
|
];
|
|
262
266
|
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
267
|
+
if (!ts) {
|
|
268
|
+
ts = require('typescript');
|
|
269
|
+
}
|
|
270
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9869
|
|
271
|
+
const supportedTSExtensions = [
|
|
272
|
+
ts.Extension.Ts,
|
|
273
|
+
ts.Extension.Tsx,
|
|
274
|
+
ts.Extension.Dts,
|
|
275
|
+
ts.Extension.Cts,
|
|
276
|
+
ts.Extension.Dcts,
|
|
277
|
+
ts.Extension.Mts,
|
|
278
|
+
ts.Extension.Dmts,
|
|
279
|
+
];
|
|
280
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9878
|
|
281
|
+
const allSupportedExtensions = [
|
|
282
|
+
ts.Extension.Ts,
|
|
283
|
+
ts.Extension.Tsx,
|
|
284
|
+
ts.Extension.Dts,
|
|
285
|
+
ts.Extension.Js,
|
|
286
|
+
ts.Extension.Jsx,
|
|
287
|
+
ts.Extension.Cts,
|
|
288
|
+
ts.Extension.Dcts,
|
|
289
|
+
ts.Extension.Cjs,
|
|
290
|
+
ts.Extension.Mts,
|
|
291
|
+
ts.Extension.Dmts,
|
|
292
|
+
ts.Extension.Mjs,
|
|
293
|
+
];
|
|
294
|
+
const normalizeInput = (input, config) => {
|
|
295
|
+
const extensions = config.options.allowJs
|
|
296
|
+
? [...allSupportedExtensions]
|
|
297
|
+
: [...supportedTSExtensions];
|
|
298
|
+
if (config.options.resolveJsonModule) {
|
|
299
|
+
extensions.push(ts.Extension.Json);
|
|
300
|
+
}
|
|
301
|
+
const segments = input.split('/');
|
|
302
|
+
// An "includes" path "foo" is implicitly a glob "foo/**/*" if its last
|
|
303
|
+
// segment has no extension, and does not contain any glob characters
|
|
304
|
+
// itself.
|
|
305
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9577-L9585
|
|
306
|
+
if (!/[.*?]/.test(segments.at(-1))) {
|
|
307
|
+
return extensions.map((ext) => `${segments.join('/')}/**/*${ext}`);
|
|
308
|
+
}
|
|
309
|
+
return [input];
|
|
310
|
+
};
|
|
263
311
|
projectTsConfigFiles.forEach(([configPath, config]) => {
|
|
264
312
|
configFiles.add(configPath);
|
|
265
313
|
const offset = (0, node_path_1.relative)(absoluteProjectRoot, (0, node_path_1.dirname)(configPath));
|
|
266
|
-
(config.raw?.include ?? []).forEach((p) =>
|
|
314
|
+
(config.raw?.include ?? []).forEach((p) => {
|
|
315
|
+
const normalized = normalizeInput((0, node_path_1.join)(offset, p), config);
|
|
316
|
+
normalized.forEach((input) => includePaths.add(input));
|
|
317
|
+
});
|
|
267
318
|
if (config.raw?.exclude) {
|
|
268
319
|
/**
|
|
269
320
|
* We need to filter out the exclude paths that are already included in
|
|
@@ -563,7 +614,6 @@ function getExtendedFilesHash(extendedConfigFile, workspaceRoot) {
|
|
|
563
614
|
}
|
|
564
615
|
return hashes.join('|');
|
|
565
616
|
}
|
|
566
|
-
let ts;
|
|
567
617
|
function readTsConfig(tsConfigPath, workspaceRoot) {
|
|
568
618
|
if (!ts) {
|
|
569
619
|
ts = require('typescript');
|
|
@@ -29,7 +29,6 @@ function addBuildAndWatchDepsTargets(workspaceRoot, projectRoot, targets, option
|
|
|
29
29
|
dependsOn: ['^build'],
|
|
30
30
|
};
|
|
31
31
|
targets[options.watchDepsTargetName ?? 'watch-deps'] = {
|
|
32
|
-
continuous: true,
|
|
33
32
|
dependsOn: [buildDepsTargetName],
|
|
34
33
|
command: `${pmc.exec} nx watch --projects ${projectName} --includeDependentProjects -- ${pmc.exec} nx ${buildDepsTargetName} ${projectName}`,
|
|
35
34
|
};
|
|
@@ -68,8 +67,8 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
68
67
|
}
|
|
69
68
|
else if (typeof value === 'object') {
|
|
70
69
|
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
71
|
-
// Skip types
|
|
72
|
-
if (currentKey === 'types') {
|
|
70
|
+
// Skip types and development conditions
|
|
71
|
+
if (currentKey === 'types' || currentKey === 'development') {
|
|
73
72
|
return false;
|
|
74
73
|
}
|
|
75
74
|
if (typeof subValue === 'string') {
|
|
@@ -33,8 +33,6 @@ export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph,
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function computeCompilerOptionsPaths(tsConfig: string | ts.ParsedCommandLine, dependencies: DependentBuildableProjectNode[]): ts.MapLike<string[]>;
|
|
35
35
|
export declare function createTmpTsConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, dependencies: DependentBuildableProjectNode[], useWorkspaceAsBaseUrl?: boolean): string;
|
|
36
|
-
export declare function checkDependentProjectsHaveBeenBuilt(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): boolean;
|
|
37
|
-
export declare function findMissingBuildDependencies(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): DependentBuildableProjectNode[];
|
|
38
36
|
export declare function updatePaths(dependencies: DependentBuildableProjectNode[], paths: Record<string, string[]>): void;
|
|
39
37
|
/**
|
|
40
38
|
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
@@ -5,8 +5,6 @@ exports.calculateProjectDependencies = calculateProjectDependencies;
|
|
|
5
5
|
exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
|
|
6
6
|
exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
|
|
7
7
|
exports.createTmpTsConfig = createTmpTsConfig;
|
|
8
|
-
exports.checkDependentProjectsHaveBeenBuilt = checkDependentProjectsHaveBeenBuilt;
|
|
9
|
-
exports.findMissingBuildDependencies = findMissingBuildDependencies;
|
|
10
8
|
exports.updatePaths = updatePaths;
|
|
11
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
12
10
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -252,36 +250,6 @@ function cleanupTmpTsConfigFile(tmpTsConfigPath) {
|
|
|
252
250
|
}
|
|
253
251
|
catch (e) { }
|
|
254
252
|
}
|
|
255
|
-
function checkDependentProjectsHaveBeenBuilt(root, projectName, targetName, projectDependencies) {
|
|
256
|
-
const missing = findMissingBuildDependencies(root, projectName, targetName, projectDependencies);
|
|
257
|
-
if (missing.length > 0) {
|
|
258
|
-
console.error((0, devkit_1.stripIndents) `
|
|
259
|
-
It looks like all of ${projectName}'s dependencies have not been built yet:
|
|
260
|
-
${missing.map((x) => ` - ${x.node.name}`).join('\n')}
|
|
261
|
-
|
|
262
|
-
You might be missing a "targetDefaults" configuration in your root nx.json (https://nx.dev/reference/project-configuration#target-defaults),
|
|
263
|
-
or "dependsOn" configured in ${projectName}'s project.json (https://nx.dev/reference/project-configuration#dependson)
|
|
264
|
-
`);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function findMissingBuildDependencies(root, projectName, targetName, projectDependencies) {
|
|
272
|
-
const depLibsToBuildFirst = [];
|
|
273
|
-
// verify whether all dependent libraries have been built
|
|
274
|
-
projectDependencies.forEach((dep) => {
|
|
275
|
-
if (dep.node.type !== 'lib') {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const paths = dep.outputs.map((p) => (0, path_1.join)(root, p));
|
|
279
|
-
if (!paths.some(fileutils_1.directoryExists)) {
|
|
280
|
-
depLibsToBuildFirst.push(dep);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return depLibsToBuildFirst;
|
|
284
|
-
}
|
|
285
253
|
function updatePaths(dependencies, paths) {
|
|
286
254
|
const pathsKeys = Object.keys(paths);
|
|
287
255
|
// For each registered dependency
|
|
@@ -291,7 +259,7 @@ function updatePaths(dependencies, paths) {
|
|
|
291
259
|
// If there are outputs
|
|
292
260
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
293
261
|
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
294
|
-
paths[dep.name] = dep.outputs;
|
|
262
|
+
paths[dep.name] = dep.outputs.map((output) => output.replace(/(\*|\/[^\/]*\*).*$/, ''));
|
|
295
263
|
// check for secondary entrypoints
|
|
296
264
|
// For each registered path
|
|
297
265
|
for (const path of pathsKeys) {
|
|
@@ -19,6 +19,7 @@ export interface UpdatePackageJsonOption {
|
|
|
19
19
|
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
|
20
20
|
generateLockfile?: boolean;
|
|
21
21
|
packageJsonPath?: string;
|
|
22
|
+
skipDevelopmentExports?: boolean;
|
|
22
23
|
}
|
|
23
24
|
export declare function updatePackageJson(options: UpdatePackageJsonOption, context: ExecutorContext, target: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], fileMap?: ProjectFileMap): void;
|
|
24
25
|
interface Exports {
|
|
@@ -50,7 +50,10 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
50
50
|
options.format = ['cjs'];
|
|
51
51
|
}
|
|
52
52
|
// update package specific settings
|
|
53
|
-
packageJson = getUpdatedPackageJsonContent(packageJson,
|
|
53
|
+
packageJson = getUpdatedPackageJsonContent(packageJson, {
|
|
54
|
+
skipDevelopmentExports: true,
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
54
57
|
// save files
|
|
55
58
|
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
56
59
|
if (options.generateLockfile) {
|
|
@@ -146,6 +149,19 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
146
149
|
packageJson.exports ??=
|
|
147
150
|
typeof packageJson.exports === 'string' ? {} : { ...packageJson.exports };
|
|
148
151
|
packageJson.exports['./package.json'] ??= './package.json';
|
|
152
|
+
if (!options.skipDevelopmentExports && (hasCjsFormat || hasEsmFormat)) {
|
|
153
|
+
packageJson.exports['.'] ??= {};
|
|
154
|
+
const developmentExports = getDevelopmentExports(options);
|
|
155
|
+
for (const [exportEntry, filePath] of Object.entries(developmentExports)) {
|
|
156
|
+
if (!packageJson.exports[exportEntry]) {
|
|
157
|
+
packageJson.exports[exportEntry] ??= {};
|
|
158
|
+
packageJson.exports[exportEntry]['development'] ??= filePath;
|
|
159
|
+
}
|
|
160
|
+
else if (typeof packageJson.exports[exportEntry] === 'object') {
|
|
161
|
+
packageJson.exports[exportEntry].development ??= filePath;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
149
165
|
}
|
|
150
166
|
if (!options.skipTypings) {
|
|
151
167
|
const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
|
|
@@ -215,6 +231,31 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
215
231
|
}
|
|
216
232
|
return packageJson;
|
|
217
233
|
}
|
|
234
|
+
function getDevelopmentExports(options) {
|
|
235
|
+
const mainRelativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
|
|
236
|
+
const exports = {
|
|
237
|
+
'.': mainRelativeDir + (0, path_1.basename)(options.main),
|
|
238
|
+
};
|
|
239
|
+
if (options.additionalEntryPoints?.length) {
|
|
240
|
+
const jsRegex = /\.[jt]sx?$/;
|
|
241
|
+
for (const file of options.additionalEntryPoints) {
|
|
242
|
+
const { ext: fileExt, name: fileName, base: baseName } = (0, path_1.parse)(file);
|
|
243
|
+
if (!jsRegex.test(fileExt)) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const relativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(file, options.projectRoot);
|
|
247
|
+
const sourceFilePath = relativeDir + baseName;
|
|
248
|
+
const entryRelativeDir = relativeDir.replace(/^\.\/src\//, './');
|
|
249
|
+
const entryFilePath = entryRelativeDir + fileName;
|
|
250
|
+
if (fileName === 'index') {
|
|
251
|
+
const barrelEntry = entryRelativeDir.replace(/\/$/, '');
|
|
252
|
+
exports[barrelEntry] = sourceFilePath;
|
|
253
|
+
}
|
|
254
|
+
exports[entryFilePath] = sourceFilePath;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return exports;
|
|
258
|
+
}
|
|
218
259
|
function getOutputDir(options) {
|
|
219
260
|
const packageJsonDir = options.packageJsonPath
|
|
220
261
|
? (0, path_1.dirname)(options.packageJsonPath)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function tsNodeRegister(file: string, tsConfig?: string): void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsNodeRegister = tsNodeRegister;
|
|
4
|
-
function tsNodeRegister(file, tsConfig) {
|
|
5
|
-
if (!file?.endsWith('.ts'))
|
|
6
|
-
return;
|
|
7
|
-
// Register TS compiler lazily
|
|
8
|
-
require('ts-node').register({
|
|
9
|
-
project: tsConfig,
|
|
10
|
-
compilerOptions: {
|
|
11
|
-
module: 'CommonJS',
|
|
12
|
-
types: ['node'],
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
if (!tsConfig)
|
|
16
|
-
return;
|
|
17
|
-
// Register paths in tsConfig
|
|
18
|
-
const tsconfigPaths = require('tsconfig-paths');
|
|
19
|
-
const { absoluteBaseUrl: baseUrl, paths } = tsconfigPaths.loadConfig(tsConfig);
|
|
20
|
-
if (baseUrl && paths) {
|
|
21
|
-
tsconfigPaths.register({ baseUrl, paths });
|
|
22
|
-
}
|
|
23
|
-
}
|