@gjsify/rolldown-plugin-gjsify 0.4.19 → 0.4.21
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/lib/utils/auto-globals.d.ts +13 -1
- package/lib/utils/auto-globals.js +40 -5
- package/package.json +7 -7
|
@@ -64,8 +64,20 @@ export interface AnalysisOptions {
|
|
|
64
64
|
* Build a `gjsifyPlugin` for the analyser to insert into the plugin array.
|
|
65
65
|
* Late-imported via dynamic `await import()` to break the cyclic dep
|
|
66
66
|
* between this file and `../plugin.ts`.
|
|
67
|
+
*
|
|
68
|
+
* Returns either the plugin array directly (legacy form) or the full
|
|
69
|
+
* orchestrator config `{ options, plugins }`. The latter shape lets
|
|
70
|
+
* `detectAutoGlobals` reuse the orchestrator's `resolve.conditionNames` /
|
|
71
|
+
* `mainFields` / `external` / `treeshake` settings for the in-memory
|
|
72
|
+
* analysis bundle — without that, native-rolldown and npm-rolldown default
|
|
73
|
+
* to different module-resolution conditions and the bundled output (and
|
|
74
|
+
* therefore the detected free-global set) diverges between engines.
|
|
67
75
|
*/
|
|
68
|
-
type
|
|
76
|
+
type GjsifyFactoryReturn = RolldownPluginOption | {
|
|
77
|
+
options: InputOptions;
|
|
78
|
+
plugins: RolldownPluginOption[];
|
|
79
|
+
};
|
|
80
|
+
type GjsifyPluginFactory = (options: PluginOptions) => GjsifyFactoryReturn | Promise<GjsifyFactoryReturn>;
|
|
69
81
|
/**
|
|
70
82
|
* Run an iterative Rolldown build (in-memory) with acorn-based global
|
|
71
83
|
* detection. Each pass uses the globals discovered by the previous pass,
|
|
@@ -70,6 +70,9 @@ function detectedToRegisterPaths(detected) {
|
|
|
70
70
|
}
|
|
71
71
|
return paths;
|
|
72
72
|
}
|
|
73
|
+
function isFullConfig(v) {
|
|
74
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v) && 'plugins' in v && 'options' in v;
|
|
75
|
+
}
|
|
73
76
|
/**
|
|
74
77
|
* Run an iterative Rolldown build (in-memory) with acorn-based global
|
|
75
78
|
* detection. Each pass uses the globals discovered by the previous pass,
|
|
@@ -105,10 +108,26 @@ export async function detectAutoGlobals(analysisOptions, pluginOptions, gjsifyPl
|
|
|
105
108
|
return name !== 'gjsify' && name !== 'gjsify-orchestrator';
|
|
106
109
|
});
|
|
107
110
|
for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
|
|
108
|
-
const
|
|
111
|
+
const factoryResult = await gjsifyPluginFactory({
|
|
109
112
|
...pluginOptions,
|
|
110
113
|
autoGlobalsInject: currentInject,
|
|
111
114
|
});
|
|
115
|
+
// Two factory shapes are supported: a plain plugin array (legacy)
|
|
116
|
+
// or the orchestrator config `{ options, plugins }`. The latter
|
|
117
|
+
// gives auto-globals access to the per-app `resolve.conditionNames`
|
|
118
|
+
// / `mainFields` / `external` / `treeshake` settings — without
|
|
119
|
+
// these, native-rolldown defaults to a different module-resolution
|
|
120
|
+
// condition set than npm-rolldown, packages resolve to different
|
|
121
|
+
// entries, and the detected global set diverges between engines.
|
|
122
|
+
let gjsifyInstance;
|
|
123
|
+
let orchestratorOptions;
|
|
124
|
+
if (isFullConfig(factoryResult)) {
|
|
125
|
+
orchestratorOptions = factoryResult.options;
|
|
126
|
+
gjsifyInstance = factoryResult.plugins;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
gjsifyInstance = factoryResult;
|
|
130
|
+
}
|
|
112
131
|
// The auto-globals inject stub is a side-effect-only ESM file that
|
|
113
132
|
// imports `<pkg>/register/<feature>` paths. Rolldown's `transform.inject`
|
|
114
133
|
// is the source-AST per-identifier rewrite we MUST NOT use (see
|
|
@@ -119,14 +138,30 @@ export async function detectAutoGlobals(analysisOptions, pluginOptions, gjsifyPl
|
|
|
119
138
|
const inputWithInject = currentInject
|
|
120
139
|
? appendInjectAsEntry(analysisOptions.input, currentInject)
|
|
121
140
|
: analysisOptions.input;
|
|
141
|
+
// Merge resolve + external + transform from the orchestrator's
|
|
142
|
+
// options so the analysis bundle goes through the same module
|
|
143
|
+
// resolution as the final build. Analysis-side overrides
|
|
144
|
+
// (`analysisOptions.*`) win when explicitly set.
|
|
145
|
+
const mergedResolve = analysisOptions.resolve ?? orchestratorOptions?.resolve;
|
|
146
|
+
const mergedExternal = analysisOptions.external ?? orchestratorOptions?.external;
|
|
147
|
+
const mergedTransform = analysisOptions.transform ?? orchestratorOptions?.transform;
|
|
148
|
+
const orchTreeshake = orchestratorOptions?.treeshake;
|
|
149
|
+
// Inline-collect both halves of the plugin chain in their existing
|
|
150
|
+
// shape: caller plugins first (PnP, user text-loaders), then the
|
|
151
|
+
// gjsify chain (which may be either a single RolldownPluginOption
|
|
152
|
+
// or an array of them depending on the factory shape).
|
|
153
|
+
const gjsifyPluginsArray = Array.isArray(gjsifyInstance)
|
|
154
|
+
? gjsifyInstance
|
|
155
|
+
: [gjsifyInstance];
|
|
122
156
|
const chunkCodes = await bundler({
|
|
123
157
|
rolldownInput: {
|
|
124
158
|
input: inputWithInject,
|
|
125
|
-
external:
|
|
126
|
-
resolve:
|
|
127
|
-
transform:
|
|
128
|
-
plugins: [...callerPlugins,
|
|
159
|
+
external: mergedExternal,
|
|
160
|
+
resolve: mergedResolve,
|
|
161
|
+
transform: mergedTransform,
|
|
162
|
+
plugins: [...callerPlugins, ...gjsifyPluginsArray],
|
|
129
163
|
logLevel: 'silent',
|
|
164
|
+
...(orchTreeshake !== undefined ? { treeshake: orchTreeshake } : {}),
|
|
130
165
|
},
|
|
131
166
|
format: analysisOptions.format ?? 'esm',
|
|
132
167
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
4
4
|
"description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
],
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@gjsify/console": "^0.4.
|
|
49
|
-
"@gjsify/resolve-npm": "^0.4.
|
|
50
|
-
"@gjsify/rolldown-plugin-deepkit": "^0.4.
|
|
51
|
-
"@gjsify/rolldown-plugin-pnp": "^0.4.
|
|
52
|
-
"@gjsify/vite-plugin-blueprint": "^0.4.
|
|
48
|
+
"@gjsify/console": "^0.4.21",
|
|
49
|
+
"@gjsify/resolve-npm": "^0.4.21",
|
|
50
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.4.21",
|
|
51
|
+
"@gjsify/rolldown-plugin-pnp": "^0.4.21",
|
|
52
|
+
"@gjsify/vite-plugin-blueprint": "^0.4.21",
|
|
53
53
|
"@rollup/pluginutils": "^5.3.0",
|
|
54
54
|
"acorn": "^8.16.0",
|
|
55
55
|
"acorn-walk": "^8.3.5",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"lightningcss": "^1.32.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@gjsify/lightningcss-native": "^0.4.
|
|
60
|
+
"@gjsify/lightningcss-native": "^0.4.21",
|
|
61
61
|
"rolldown": "^1.0.0-rc.18"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|