@nx/rollup 16.6.0-beta.6 → 16.6.0-beta.8
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 +6 -5
- package/src/executors/rollup/lib/normalize.d.ts +2 -1
- package/src/executors/rollup/lib/normalize.js +12 -2
- package/src/executors/rollup/lib/update-package-json.js +49 -23
- package/src/executors/rollup/rollup.impl.js +24 -23
- package/src/executors/rollup/schema.d.ts +2 -1
- package/src/executors/rollup/schema.json +12 -2
- package/src/generators/configuration/configuration.js +1 -1
- package/src/executors/rollup/lib/validate-types.d.ts +0 -5
- package/src/executors/rollup/lib/validate-types.js +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rollup",
|
|
3
|
-
"version": "16.6.0-beta.
|
|
3
|
+
"version": "16.6.0-beta.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Rollup contains executors and generators that support building applications using Rollup.",
|
|
6
6
|
"repository": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nrwl/rollup": "16.6.0-beta.
|
|
33
|
-
"@nx/devkit": "16.6.0-beta.
|
|
34
|
-
"@nx/js": "16.6.0-beta.
|
|
32
|
+
"@nrwl/rollup": "16.6.0-beta.8",
|
|
33
|
+
"@nx/devkit": "16.6.0-beta.8",
|
|
34
|
+
"@nx/js": "16.6.0-beta.8",
|
|
35
35
|
"@rollup/plugin-babel": "^5.3.0",
|
|
36
36
|
"@rollup/plugin-commonjs": "^20.0.0",
|
|
37
37
|
"@rollup/plugin-image": "^2.1.0",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"babel-plugin-transform-async-to-promises": "^0.8.15",
|
|
42
42
|
"chalk": "^4.1.0",
|
|
43
43
|
"dotenv": "~10.0.0",
|
|
44
|
+
"fast-glob": "^3.2.7",
|
|
44
45
|
"postcss": "^8.4.14",
|
|
45
46
|
"rollup": "^2.56.2",
|
|
46
47
|
"rollup-plugin-copy": "^3.4.0",
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"access": "public"
|
|
55
56
|
},
|
|
56
57
|
"types": "./index.d.ts",
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "d1d06349e703d903ac47fb7adc7d250ce140d77e"
|
|
58
59
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
1
2
|
import type { AssetGlobPattern, RollupExecutorOptions } from '../schema';
|
|
2
3
|
export interface NormalizedRollupExecutorOptions extends RollupExecutorOptions {
|
|
3
4
|
entryRoot: string;
|
|
@@ -5,6 +6,6 @@ export interface NormalizedRollupExecutorOptions extends RollupExecutorOptions {
|
|
|
5
6
|
assets: AssetGlobPattern[];
|
|
6
7
|
rollupConfig: string[];
|
|
7
8
|
}
|
|
8
|
-
export declare function normalizeRollupExecutorOptions(options: RollupExecutorOptions,
|
|
9
|
+
export declare function normalizeRollupExecutorOptions(options: RollupExecutorOptions, context: ExecutorContext, sourceRoot: string): NormalizedRollupExecutorOptions;
|
|
9
10
|
export declare function normalizePluginPath(pluginPath: void | string, root: string): string;
|
|
10
11
|
export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string): AssetGlobPattern[];
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeAssets = exports.normalizePluginPath = exports.normalizeRollupExecutorOptions = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const fast_glob_1 = require("fast-glob");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
function normalizeRollupExecutorOptions(options,
|
|
8
|
+
function normalizeRollupExecutorOptions(options, context, sourceRoot) {
|
|
9
|
+
const { root } = context;
|
|
8
10
|
const main = `${root}/${options.main}`;
|
|
9
11
|
const entryRoot = (0, path_1.dirname)(main);
|
|
10
12
|
const project = options.project
|
|
@@ -26,7 +28,7 @@ function normalizeRollupExecutorOptions(options, root, sourceRoot) {
|
|
|
26
28
|
entryRoot,
|
|
27
29
|
project,
|
|
28
30
|
projectRoot,
|
|
29
|
-
outputPath, skipTypeCheck: options.skipTypeCheck || false });
|
|
31
|
+
outputPath, skipTypeCheck: options.skipTypeCheck || false, additionalEntryPoints: createEntryPoints(options, context) });
|
|
30
32
|
}
|
|
31
33
|
exports.normalizeRollupExecutorOptions = normalizeRollupExecutorOptions;
|
|
32
34
|
function normalizePluginPath(pluginPath, root) {
|
|
@@ -75,3 +77,11 @@ function normalizeAssets(assets, root, sourceRoot) {
|
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
exports.normalizeAssets = normalizeAssets;
|
|
80
|
+
function createEntryPoints(options, context) {
|
|
81
|
+
var _a;
|
|
82
|
+
if (!((_a = options.additionalEntryPoints) === null || _a === void 0 ? void 0 : _a.length))
|
|
83
|
+
return [];
|
|
84
|
+
return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
|
|
85
|
+
cwd: context.root,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -4,37 +4,48 @@ exports.updatePackageJson = void 0;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
|
|
6
6
|
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
7
|
+
// TODO(jack): Use updatePackageJson from @nx/js instead.
|
|
7
8
|
function updatePackageJson(options, context, target, dependencies, packageJson) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
var _c;
|
|
8
11
|
const hasEsmFormat = options.format.includes('esm');
|
|
9
12
|
const hasCjsFormat = options.format.includes('cjs');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'.'
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
};
|
|
13
|
+
if (options.generateExportsField) {
|
|
14
|
+
packageJson.exports =
|
|
15
|
+
typeof packageJson.exports === 'string' ? {} : Object.assign({}, packageJson.exports);
|
|
16
|
+
packageJson.exports['./package.json'] = './package.json';
|
|
17
|
+
}
|
|
17
18
|
if (hasEsmFormat) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
packageJson.module = './index.js';
|
|
21
|
-
exports['.']['import'] = './index.js';
|
|
19
|
+
const esmExports = getExports(Object.assign(Object.assign({}, options), { fileExt: '.esm.js' }));
|
|
20
|
+
packageJson.module = esmExports['.'];
|
|
22
21
|
if (!hasCjsFormat) {
|
|
23
|
-
packageJson.
|
|
22
|
+
packageJson.type = 'module';
|
|
23
|
+
(_a = packageJson.main) !== null && _a !== void 0 ? _a : (packageJson.main = esmExports['.']);
|
|
24
|
+
}
|
|
25
|
+
if (options.generateExportsField) {
|
|
26
|
+
for (const [exportEntry, filePath] of Object.entries(esmExports)) {
|
|
27
|
+
packageJson.exports[exportEntry] = hasCjsFormat
|
|
28
|
+
? { import: filePath }
|
|
29
|
+
: filePath;
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
if (hasCjsFormat) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const cjsExports = getExports(Object.assign(Object.assign({}, options), { fileExt: '.cjs.js' }));
|
|
35
|
+
packageJson.main = cjsExports['.'];
|
|
36
|
+
if (!hasEsmFormat) {
|
|
37
|
+
packageJson.type = 'commonjs';
|
|
38
|
+
}
|
|
39
|
+
if (options.generateExportsField) {
|
|
40
|
+
for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
|
|
41
|
+
if (hasEsmFormat) {
|
|
42
|
+
(_b = (_c = packageJson.exports[exportEntry])['default']) !== null && _b !== void 0 ? _b : (_c['default'] = filePath);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
packageJson.exports[exportEntry] = filePath;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
}
|
|
39
50
|
(0, fileutils_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
40
51
|
if (dependencies.length > 0 &&
|
|
@@ -43,3 +54,18 @@ function updatePackageJson(options, context, target, dependencies, packageJson)
|
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
56
|
exports.updatePackageJson = updatePackageJson;
|
|
57
|
+
function getExports(options) {
|
|
58
|
+
const mainFile = options.outputFileName
|
|
59
|
+
? options.outputFileName.replace(/\.[tj]s$/, '')
|
|
60
|
+
: (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
|
|
61
|
+
const exports = {
|
|
62
|
+
'.': './' + mainFile + options.fileExt,
|
|
63
|
+
};
|
|
64
|
+
if (options.additionalEntryPoints) {
|
|
65
|
+
for (const file of options.additionalEntryPoints) {
|
|
66
|
+
const { name: fileName } = (0, path_1.parse)(file);
|
|
67
|
+
exports['./' + fileName] = './' + fileName + options.fileExt;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return exports;
|
|
71
|
+
}
|
|
@@ -20,8 +20,8 @@ const normalize_1 = require("./lib/normalize");
|
|
|
20
20
|
const analyze_plugin_1 = require("./lib/analyze-plugin");
|
|
21
21
|
const fs_1 = require("../../utils/fs");
|
|
22
22
|
const swc_plugin_1 = require("./lib/swc-plugin");
|
|
23
|
-
const validate_types_1 = require("./lib/validate-types");
|
|
24
23
|
const update_package_json_1 = require("./lib/update-package-json");
|
|
24
|
+
const type_definitions_1 = require("@nx/js/src/plugins/rollup/type-definitions");
|
|
25
25
|
// These use require because the ES import isn't correct.
|
|
26
26
|
const commonjs = require('@rollup/plugin-commonjs');
|
|
27
27
|
const image = require('@rollup/plugin-image');
|
|
@@ -37,25 +37,13 @@ function rollupExecutor(rawOptions, context) {
|
|
|
37
37
|
const project = context.projectsConfigurations.projects[context.projectName];
|
|
38
38
|
const sourceRoot = project.sourceRoot;
|
|
39
39
|
const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName, true);
|
|
40
|
-
const options = (0, normalize_1.normalizeRollupExecutorOptions)(rawOptions, context
|
|
40
|
+
const options = (0, normalize_1.normalizeRollupExecutorOptions)(rawOptions, context, sourceRoot);
|
|
41
41
|
const packageJson = (0, devkit_1.readJsonFile)(options.project);
|
|
42
42
|
const npmDeps = ((_b = context.projectGraph.dependencies[context.projectName]) !== null && _b !== void 0 ? _b : [])
|
|
43
43
|
.filter((d) => d.target.startsWith('npm:'))
|
|
44
44
|
.map((d) => d.target.slice(4));
|
|
45
45
|
const rollupOptions = createRollupOptions(options, dependencies, context, packageJson, sourceRoot, npmDeps);
|
|
46
46
|
const outfile = resolveOutfile(context, options);
|
|
47
|
-
if (options.compiler === 'swc') {
|
|
48
|
-
try {
|
|
49
|
-
yield tslib_1.__await((0, validate_types_1.validateTypes)({
|
|
50
|
-
workspaceRoot: context.root,
|
|
51
|
-
projectRoot: options.projectRoot,
|
|
52
|
-
tsconfig: options.tsConfig,
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
catch (_d) {
|
|
56
|
-
return yield tslib_1.__await({ success: false });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
47
|
if (options.watch) {
|
|
60
48
|
const watcher = rollup.watch(rollupOptions);
|
|
61
49
|
return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, rxjs_for_await_1.eachValueFrom)(new rxjs_1.Observable((obs) => {
|
|
@@ -122,13 +110,16 @@ function createRollupOptions(options, dependencies, context, packageJson, source
|
|
|
122
110
|
options.format = readCompatibleFormats(config);
|
|
123
111
|
}
|
|
124
112
|
return options.format.map((format, idx) => {
|
|
113
|
+
// Either we're generating only one format, so we should bundle types
|
|
114
|
+
// OR we are generating dual formats, so only bundle types for CJS.
|
|
115
|
+
const shouldBundleTypes = options.format.length === 1 || format === 'cjs';
|
|
125
116
|
const plugins = [
|
|
126
117
|
copy({
|
|
127
118
|
targets: convertCopyAssetsToRollupOptions(options.outputPath, options.assets),
|
|
128
119
|
}),
|
|
129
120
|
image(),
|
|
130
121
|
json(),
|
|
131
|
-
(useTsc ||
|
|
122
|
+
(useTsc || shouldBundleTypes) &&
|
|
132
123
|
require('rollup-plugin-typescript2')({
|
|
133
124
|
check: !options.skipTypeCheck,
|
|
134
125
|
tsconfig: options.tsConfig,
|
|
@@ -136,6 +127,11 @@ function createRollupOptions(options, dependencies, context, packageJson, source
|
|
|
136
127
|
compilerOptions: createTsCompilerOptions(config, dependencies, options),
|
|
137
128
|
},
|
|
138
129
|
}),
|
|
130
|
+
shouldBundleTypes &&
|
|
131
|
+
(0, type_definitions_1.typeDefinitions)({
|
|
132
|
+
main: options.main,
|
|
133
|
+
projectRoot: options.projectRoot,
|
|
134
|
+
}),
|
|
139
135
|
peerDepsExternal({
|
|
140
136
|
packageJsonPath: options.project,
|
|
141
137
|
}),
|
|
@@ -195,18 +191,20 @@ function createRollupOptions(options, dependencies, context, packageJson, source
|
|
|
195
191
|
externalPackages = externalPackages.concat(options.external);
|
|
196
192
|
}
|
|
197
193
|
externalPackages = [...new Set(externalPackages)];
|
|
194
|
+
const mainEntryFileName = options.outputFileName || options.main;
|
|
195
|
+
const input = {};
|
|
196
|
+
input[(0, path_1.parse)(mainEntryFileName).name] = options.main;
|
|
197
|
+
options.additionalEntryPoints.forEach((entry) => {
|
|
198
|
+
input[(0, path_1.parse)(entry).name] = entry;
|
|
199
|
+
});
|
|
198
200
|
const rollupConfig = {
|
|
199
|
-
input
|
|
200
|
-
? {
|
|
201
|
-
[(0, path_1.parse)(options.outputFileName).name]: options.main,
|
|
202
|
-
}
|
|
203
|
-
: options.main,
|
|
201
|
+
input,
|
|
204
202
|
output: {
|
|
205
203
|
format,
|
|
206
204
|
dir: `${options.outputPath}`,
|
|
207
205
|
name: (0, devkit_1.names)(context.projectName).className,
|
|
208
|
-
entryFileNames: `[name].${format
|
|
209
|
-
chunkFileNames: `[name].${format
|
|
206
|
+
entryFileNames: `[name].${format}.js`,
|
|
207
|
+
chunkFileNames: `[name].${format}.js`,
|
|
210
208
|
},
|
|
211
209
|
external: (id) => {
|
|
212
210
|
return externalPackages.some((name) => id === name || id.startsWith(`${name}/`)); // Could be a deep import
|
|
@@ -230,6 +228,9 @@ function createTsCompilerOptions(config, dependencies, options) {
|
|
|
230
228
|
if (config.options.module === ts.ModuleKind.CommonJS) {
|
|
231
229
|
compilerOptions['module'] = 'ESNext';
|
|
232
230
|
}
|
|
231
|
+
if (options.compiler === 'swc') {
|
|
232
|
+
compilerOptions['emitDeclarationOnly'] = true;
|
|
233
|
+
}
|
|
233
234
|
return compilerOptions;
|
|
234
235
|
}
|
|
235
236
|
function convertCopyAssetsToRollupOptions(outputPath, assets) {
|
|
@@ -255,6 +256,6 @@ function resolveOutfile(context, options) {
|
|
|
255
256
|
if (!((_a = options.format) === null || _a === void 0 ? void 0 : _a.includes('cjs')))
|
|
256
257
|
return undefined;
|
|
257
258
|
const { name } = (0, path_1.parse)((_b = options.outputFileName) !== null && _b !== void 0 ? _b : options.main);
|
|
258
|
-
return (0, path_1.resolve)(context.root, options.outputPath, `${name}.cjs`);
|
|
259
|
+
return (0, path_1.resolve)(context.root, options.outputPath, `${name}.cjs.js`);
|
|
259
260
|
}
|
|
260
261
|
exports.default = rollupExecutor;
|
|
@@ -37,10 +37,11 @@ export interface RollupExecutorOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
|
39
39
|
deleteOutputPath?: boolean;
|
|
40
|
-
format?:
|
|
40
|
+
format?: ('cjs' | 'esm')[];
|
|
41
41
|
compiler?: 'babel' | 'tsc' | 'swc';
|
|
42
42
|
javascriptEnabled?: boolean;
|
|
43
43
|
generateExportsField?: boolean;
|
|
44
|
+
additionalEntryPoints?: string[];
|
|
44
45
|
skipTypeCheck?: boolean;
|
|
45
46
|
babelUpwardRootMode?: boolean;
|
|
46
47
|
skipTypeField?: boolean;
|
|
@@ -138,8 +138,18 @@
|
|
|
138
138
|
},
|
|
139
139
|
"generateExportsField": {
|
|
140
140
|
"type": "boolean",
|
|
141
|
-
"
|
|
142
|
-
"
|
|
141
|
+
"alias": "exports",
|
|
142
|
+
"description": "Update the output package.json file's 'exports' field. This field is used by Node and bundles.",
|
|
143
|
+
"default": false,
|
|
144
|
+
"x-priority": "important"
|
|
145
|
+
},
|
|
146
|
+
"additionalEntryPoints": {
|
|
147
|
+
"type": "array",
|
|
148
|
+
"description": "Additional entry-points to add to exports field in the package.json file.",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "string"
|
|
151
|
+
},
|
|
152
|
+
"x-priority": "important"
|
|
143
153
|
},
|
|
144
154
|
"skipTypeCheck": {
|
|
145
155
|
"type": "boolean",
|
|
@@ -40,7 +40,7 @@ function addBuildTarget(tree, options) {
|
|
|
40
40
|
const tsConfig = (_a = options.tsConfig) !== null && _a !== void 0 ? _a : (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
|
|
41
41
|
const buildOptions = {
|
|
42
42
|
main: (_b = options.main) !== null && _b !== void 0 ? _b : (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts'),
|
|
43
|
-
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root),
|
|
43
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root),
|
|
44
44
|
compiler: (_c = options.compiler) !== null && _c !== void 0 ? _c : 'babel',
|
|
45
45
|
tsConfig,
|
|
46
46
|
project: `${project.root}/package.json`,
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateTypes = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const js_1 = require("@nx/js");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
function validateTypes(opts) {
|
|
8
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
-
const result = yield (0, js_1.runTypeCheck)({
|
|
10
|
-
workspaceRoot: opts.workspaceRoot,
|
|
11
|
-
tsConfigPath: (0, path_1.join)(opts.workspaceRoot, opts.tsconfig),
|
|
12
|
-
mode: 'noEmit',
|
|
13
|
-
});
|
|
14
|
-
yield (0, js_1.printDiagnostics)(result.errors, result.warnings);
|
|
15
|
-
if (result.errors.length > 0) {
|
|
16
|
-
throw new Error('Found type errors. See above.');
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
exports.validateTypes = validateTypes;
|