@nx/rollup 20.1.0-canary.20241102-c290b37 → 20.1.0-canary.20241105-b925f8c
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/plugin.d.ts +1 -1
- package/plugin.js +2 -1
- package/src/plugins/plugin.d.ts +5 -1
- package/src/plugins/plugin.js +63 -33
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/rollup",
|
3
|
-
"version": "20.1.0-canary.
|
3
|
+
"version": "20.1.0-canary.20241105-b925f8c",
|
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": {
|
@@ -43,8 +43,8 @@
|
|
43
43
|
"rollup-plugin-postcss": "^4.0.2",
|
44
44
|
"rollup-plugin-typescript2": "^0.36.0",
|
45
45
|
"tslib": "^2.3.0",
|
46
|
-
"@nx/devkit": "20.1.0-canary.
|
47
|
-
"@nx/js": "20.1.0-canary.
|
46
|
+
"@nx/devkit": "20.1.0-canary.20241105-b925f8c",
|
47
|
+
"@nx/js": "20.1.0-canary.20241105-b925f8c"
|
48
48
|
},
|
49
49
|
"publishConfig": {
|
50
50
|
"access": "public"
|
package/plugin.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { createNodes, RollupPluginOptions } from './src/plugins/plugin';
|
1
|
+
export { createNodes, createNodesV2, RollupPluginOptions, } from './src/plugins/plugin';
|
package/plugin.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createNodes = void 0;
|
3
|
+
exports.createNodesV2 = exports.createNodes = void 0;
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
5
5
|
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
6
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
package/src/plugins/plugin.d.ts
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
import { type CreateDependencies, type CreateNodes } from '@nx/devkit';
|
1
|
+
import { type CreateDependencies, type CreateNodes, CreateNodesV2 } from '@nx/devkit';
|
2
|
+
/**
|
3
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
4
|
+
*/
|
2
5
|
export declare const createDependencies: CreateDependencies;
|
3
6
|
export interface RollupPluginOptions {
|
4
7
|
buildTargetName?: string;
|
5
8
|
}
|
6
9
|
export declare const createNodes: CreateNodes<RollupPluginOptions>;
|
10
|
+
export declare const createNodesV2: CreateNodesV2<RollupPluginOptions>;
|
package/src/plugins/plugin.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
3
|
+
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
4
4
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
5
5
|
const path_1 = require("path");
|
6
6
|
const fs_1 = require("fs");
|
@@ -8,47 +8,64 @@ const devkit_1 = require("@nx/devkit");
|
|
8
8
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
9
9
|
const js_1 = require("@nx/js");
|
10
10
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
11
|
-
const
|
12
|
-
const
|
13
|
-
function readTargetsCache() {
|
11
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
12
|
+
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
13
|
+
function readTargetsCache(cachePath) {
|
14
14
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
15
15
|
}
|
16
|
-
function writeTargetsToCache() {
|
17
|
-
|
18
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
19
|
-
...oldCache,
|
20
|
-
...targetsCache,
|
21
|
-
});
|
16
|
+
function writeTargetsToCache(cachePath, results) {
|
17
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
22
18
|
}
|
19
|
+
/**
|
20
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
21
|
+
*/
|
23
22
|
const createDependencies = () => {
|
24
|
-
writeTargetsToCache();
|
25
23
|
return [];
|
26
24
|
};
|
27
25
|
exports.createDependencies = createDependencies;
|
26
|
+
const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs}';
|
28
27
|
exports.createNodes = [
|
29
|
-
|
28
|
+
rollupConfigGlob,
|
30
29
|
async (configFilePath, options, context) => {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
31
|
+
return createNodesInternal(configFilePath, normalizeOptions(options), context, {});
|
32
|
+
},
|
33
|
+
];
|
34
|
+
exports.createNodesV2 = [
|
35
|
+
rollupConfigGlob,
|
36
|
+
async (configFilePaths, options, context) => {
|
37
|
+
const normalizedOptions = normalizeOptions(options);
|
38
|
+
const optionsHash = (0, file_hasher_1.hashObject)(normalizedOptions);
|
39
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rollup-${optionsHash}.hash`);
|
40
|
+
const targetsCache = readTargetsCache(cachePath);
|
41
|
+
try {
|
42
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, _, context) => createNodesInternal(configFile, normalizedOptions, context, targetsCache), configFilePaths, normalizedOptions, context);
|
43
|
+
}
|
44
|
+
finally {
|
45
|
+
writeTargetsToCache(cachePath, targetsCache);
|
38
46
|
}
|
39
|
-
options = normalizeOptions(options);
|
40
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
41
|
-
targetsCache[hash] ??= await buildRollupTarget(configFilePath, projectRoot, options, context);
|
42
|
-
return {
|
43
|
-
projects: {
|
44
|
-
[projectRoot]: {
|
45
|
-
root: projectRoot,
|
46
|
-
targets: targetsCache[hash],
|
47
|
-
},
|
48
|
-
},
|
49
|
-
};
|
50
47
|
},
|
51
48
|
];
|
49
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache) {
|
50
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
51
|
+
const fullyQualifiedProjectRoot = (0, path_1.join)(context.workspaceRoot, projectRoot);
|
52
|
+
// Do not create a project if package.json and project.json do not exist
|
53
|
+
const siblingFiles = (0, fs_1.readdirSync)(fullyQualifiedProjectRoot);
|
54
|
+
if (!siblingFiles.includes('package.json') &&
|
55
|
+
!siblingFiles.includes('project.json')) {
|
56
|
+
return {};
|
57
|
+
}
|
58
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
59
|
+
targetsCache[hash] ??= await buildRollupTarget(configFilePath, projectRoot, options, context);
|
60
|
+
return {
|
61
|
+
projects: {
|
62
|
+
[projectRoot]: {
|
63
|
+
root: projectRoot,
|
64
|
+
targets: targetsCache[hash],
|
65
|
+
},
|
66
|
+
},
|
67
|
+
};
|
68
|
+
}
|
52
69
|
async function buildRollupTarget(configFilePath, projectRoot, options, context) {
|
53
70
|
let loadConfigFile;
|
54
71
|
try {
|
@@ -83,6 +100,19 @@ async function buildRollupTarget(configFilePath, projectRoot, options, context)
|
|
83
100
|
{ externalDependencies: ['rollup'] },
|
84
101
|
],
|
85
102
|
outputs,
|
103
|
+
metadata: {
|
104
|
+
technologies: ['rollup'],
|
105
|
+
description: 'Run Rollup',
|
106
|
+
help: {
|
107
|
+
command: `${pmc.exec} rollup --help`,
|
108
|
+
example: {
|
109
|
+
options: {
|
110
|
+
sourcemap: true,
|
111
|
+
watch: true,
|
112
|
+
},
|
113
|
+
},
|
114
|
+
},
|
115
|
+
},
|
86
116
|
};
|
87
117
|
return targets;
|
88
118
|
}
|
@@ -113,7 +143,7 @@ function getOutputs(rollupConfigs, projectRoot) {
|
|
113
143
|
return Array.from(outputs);
|
114
144
|
}
|
115
145
|
function normalizeOptions(options) {
|
116
|
-
|
117
|
-
|
118
|
-
|
146
|
+
return {
|
147
|
+
buildTargetName: options.buildTargetName ?? 'build',
|
148
|
+
};
|
119
149
|
}
|