with-zephyr 0.0.0-canary.4 → 0.0.0-canary.5
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/dist/index.js +14 -118
- package/package.json +2 -2
- package/dist/zephyr-manifest.json +0 -6
package/dist/index.js
CHANGED
|
@@ -48139,20 +48139,15 @@ const BUNDLER_CONFIGS = {
|
|
|
48139
48139
|
plugin: 'zephyr-rsbuild-plugin',
|
|
48140
48140
|
importName: 'withZephyr',
|
|
48141
48141
|
patterns: [
|
|
48142
|
-
{
|
|
48143
|
-
type: 'zephyr-rsbuild-plugin-exists',
|
|
48144
|
-
matcher: /zephyrRSbuildPlugin/,
|
|
48145
|
-
transform: 'skipAlreadyWrapped'
|
|
48146
|
-
},
|
|
48147
48142
|
{
|
|
48148
48143
|
type: 'define-config',
|
|
48149
48144
|
matcher: /defineConfig\s*\(\s*\{/,
|
|
48150
|
-
transform: '
|
|
48145
|
+
transform: 'addToPluginsArray'
|
|
48151
48146
|
},
|
|
48152
48147
|
{
|
|
48153
48148
|
type: 'plugins-array',
|
|
48154
48149
|
matcher: /plugins\s*:\s*\[/,
|
|
48155
|
-
transform: '
|
|
48150
|
+
transform: 'addToPluginsArray'
|
|
48156
48151
|
}
|
|
48157
48152
|
]
|
|
48158
48153
|
},
|
|
@@ -48165,25 +48160,27 @@ const BUNDLER_CONFIGS = {
|
|
|
48165
48160
|
plugin: 'zephyr-rsbuild-plugin',
|
|
48166
48161
|
importName: 'withZephyr',
|
|
48167
48162
|
patterns: [
|
|
48168
|
-
{
|
|
48169
|
-
type: 'zephyr-rsbuild-plugin-exists',
|
|
48170
|
-
matcher: /zephyrRSbuildPlugin/,
|
|
48171
|
-
transform: 'skipAlreadyWrapped'
|
|
48172
|
-
},
|
|
48173
48163
|
{
|
|
48174
48164
|
type: 'define-config',
|
|
48175
48165
|
matcher: /defineConfig\s*\(\s*\{/,
|
|
48176
|
-
transform: '
|
|
48166
|
+
transform: 'addToPluginsArray'
|
|
48177
48167
|
},
|
|
48178
48168
|
{
|
|
48179
48169
|
type: 'plugins-array',
|
|
48180
48170
|
matcher: /plugins\s*:\s*\[/,
|
|
48181
|
-
transform: '
|
|
48171
|
+
transform: 'addToPluginsArray'
|
|
48182
48172
|
}
|
|
48183
48173
|
]
|
|
48184
48174
|
}
|
|
48185
48175
|
};
|
|
48186
48176
|
function detectPackageManager(directory = process.cwd()) {
|
|
48177
|
+
if (process.env.npm_config_user_agent) {
|
|
48178
|
+
const userAgent = process.env.npm_config_user_agent.toLowerCase();
|
|
48179
|
+
if (userAgent.includes('pnpm')) return 'pnpm';
|
|
48180
|
+
if (userAgent.includes('yarn')) return 'yarn';
|
|
48181
|
+
if (userAgent.includes('bun')) return 'bun';
|
|
48182
|
+
if (userAgent.includes('npm')) return 'npm';
|
|
48183
|
+
}
|
|
48187
48184
|
const lockFiles = {
|
|
48188
48185
|
'pnpm-lock.yaml': 'pnpm',
|
|
48189
48186
|
'yarn.lock': 'yarn',
|
|
@@ -48216,12 +48213,6 @@ function detectPackageManager(directory = process.cwd()) {
|
|
|
48216
48213
|
if (fs_0.existsSync(path_0.join(rootDir, 'lerna.json')) || fs_0.existsSync(path_0.join(rootDir, 'yarn.lock')) && rootDir === directory) return 'yarn';
|
|
48217
48214
|
}
|
|
48218
48215
|
} catch {}
|
|
48219
|
-
if (process.env.npm_config_user_agent) {
|
|
48220
|
-
const userAgent = process.env.npm_config_user_agent.toLowerCase();
|
|
48221
|
-
if (userAgent.includes('pnpm')) return 'pnpm';
|
|
48222
|
-
if (userAgent.includes('yarn')) return 'yarn';
|
|
48223
|
-
if (userAgent.includes('bun')) return 'bun';
|
|
48224
|
-
}
|
|
48225
48216
|
return 'npm';
|
|
48226
48217
|
}
|
|
48227
48218
|
function isPackageInstalled(packageName, directory = process.cwd()) {
|
|
@@ -48348,7 +48339,7 @@ function addZephyrRequire(ast, pluginName, importName) {
|
|
|
48348
48339
|
});
|
|
48349
48340
|
}
|
|
48350
48341
|
}
|
|
48351
|
-
function
|
|
48342
|
+
function hasZephyrPlugin(ast) {
|
|
48352
48343
|
let hasPlugin = false;
|
|
48353
48344
|
(0, traverse_lib["default"])(ast, {
|
|
48354
48345
|
CallExpression (path) {
|
|
@@ -48498,100 +48489,6 @@ function wrapExportedFunction(ast) {
|
|
|
48498
48489
|
}
|
|
48499
48490
|
});
|
|
48500
48491
|
}
|
|
48501
|
-
function addZephyrRSbuildPlugin(ast) {
|
|
48502
|
-
let hasWithZephyrImport = false;
|
|
48503
|
-
(0, traverse_lib["default"])(ast, {
|
|
48504
|
-
ImportDeclaration (path) {
|
|
48505
|
-
if ('zephyr-rspack-plugin' === path.node.source.value) {
|
|
48506
|
-
const specifiers = path.node.specifiers;
|
|
48507
|
-
for (const spec of specifiers)if (types_lib.isImportSpecifier(spec) && types_lib.isIdentifier(spec.imported, {
|
|
48508
|
-
name: 'withZephyr'
|
|
48509
|
-
})) hasWithZephyrImport = true;
|
|
48510
|
-
}
|
|
48511
|
-
}
|
|
48512
|
-
});
|
|
48513
|
-
if (!hasWithZephyrImport) {
|
|
48514
|
-
const importDeclaration = types_lib.importDeclaration([
|
|
48515
|
-
types_lib.importSpecifier(types_lib.identifier('withZephyr'), types_lib.identifier('withZephyr'))
|
|
48516
|
-
], types_lib.stringLiteral('zephyr-rspack-plugin'));
|
|
48517
|
-
(0, traverse_lib["default"])(ast, {
|
|
48518
|
-
Program (path) {
|
|
48519
|
-
const firstImportIndex = path.node.body.findIndex((node)=>types_lib.isImportDeclaration(node));
|
|
48520
|
-
if (firstImportIndex >= 0) path.node.body.splice(firstImportIndex + 1, 0, importDeclaration);
|
|
48521
|
-
else path.node.body.unshift(importDeclaration);
|
|
48522
|
-
path.stop();
|
|
48523
|
-
}
|
|
48524
|
-
});
|
|
48525
|
-
}
|
|
48526
|
-
let hasZephyrPlugin = false;
|
|
48527
|
-
(0, traverse_lib["default"])(ast, {
|
|
48528
|
-
VariableDeclarator (path) {
|
|
48529
|
-
if (types_lib.isIdentifier(path.node.id, {
|
|
48530
|
-
name: 'zephyrRSbuildPlugin'
|
|
48531
|
-
})) hasZephyrPlugin = true;
|
|
48532
|
-
}
|
|
48533
|
-
});
|
|
48534
|
-
if (!hasZephyrPlugin) {
|
|
48535
|
-
const zephyrPluginFunction = types_lib.variableDeclaration('const', [
|
|
48536
|
-
types_lib.variableDeclarator(types_lib.identifier('zephyrRSbuildPlugin'), types_lib.arrowFunctionExpression([], types_lib.objectExpression([
|
|
48537
|
-
types_lib.objectProperty(types_lib.identifier('name'), types_lib.stringLiteral('zephyr-rsbuild-plugin')),
|
|
48538
|
-
types_lib.objectMethod('method', types_lib.identifier('setup'), [
|
|
48539
|
-
types_lib.identifier('api')
|
|
48540
|
-
], types_lib.blockStatement([
|
|
48541
|
-
types_lib.expressionStatement(types_lib.callExpression(types_lib.memberExpression(types_lib.identifier('api'), types_lib.identifier('modifyRspackConfig')), [
|
|
48542
|
-
types_lib.arrowFunctionExpression([
|
|
48543
|
-
types_lib.identifier('config')
|
|
48544
|
-
], types_lib.blockStatement([
|
|
48545
|
-
types_lib.variableDeclaration('const', [
|
|
48546
|
-
types_lib.variableDeclarator(types_lib.identifier('zephyrConfig'), types_lib.awaitExpression(types_lib.callExpression(types_lib.callExpression(types_lib.identifier('withZephyr'), []), [
|
|
48547
|
-
types_lib.identifier('config')
|
|
48548
|
-
])))
|
|
48549
|
-
]),
|
|
48550
|
-
types_lib.expressionStatement(types_lib.assignmentExpression('=', types_lib.identifier('config'), types_lib.identifier('zephyrConfig')))
|
|
48551
|
-
]), true)
|
|
48552
|
-
]))
|
|
48553
|
-
]))
|
|
48554
|
-
])))
|
|
48555
|
-
]);
|
|
48556
|
-
(0, traverse_lib["default"])(ast, {
|
|
48557
|
-
Program (path) {
|
|
48558
|
-
let insertIndex = 0;
|
|
48559
|
-
for(let i = 0; i < path.node.body.length; i++)if (types_lib.isImportDeclaration(path.node.body[i])) insertIndex = i + 1;
|
|
48560
|
-
else break;
|
|
48561
|
-
path.node.body.splice(insertIndex, 0, zephyrPluginFunction);
|
|
48562
|
-
path.stop();
|
|
48563
|
-
}
|
|
48564
|
-
});
|
|
48565
|
-
let hasRsbuildPluginImport = false;
|
|
48566
|
-
(0, traverse_lib["default"])(ast, {
|
|
48567
|
-
ImportDeclaration (path) {
|
|
48568
|
-
if ('@rsbuild/core' === path.node.source.value) {
|
|
48569
|
-
const specifiers = path.node.specifiers;
|
|
48570
|
-
for (const spec of specifiers)if (types_lib.isImportSpecifier(spec) && types_lib.isIdentifier(spec.imported, {
|
|
48571
|
-
name: 'RsbuildPlugin'
|
|
48572
|
-
})) hasRsbuildPluginImport = true;
|
|
48573
|
-
if (!hasRsbuildPluginImport) specifiers.push(types_lib.importSpecifier(types_lib.identifier('RsbuildPlugin'), types_lib.identifier('RsbuildPlugin')));
|
|
48574
|
-
}
|
|
48575
|
-
}
|
|
48576
|
-
});
|
|
48577
|
-
}
|
|
48578
|
-
(0, traverse_lib["default"])(ast, {
|
|
48579
|
-
ObjectProperty (path) {
|
|
48580
|
-
if (types_lib.isIdentifier(path.node.key, {
|
|
48581
|
-
name: 'plugins'
|
|
48582
|
-
}) && types_lib.isArrayExpression(path.node.value)) {
|
|
48583
|
-
let hasZephyrInPlugins = false;
|
|
48584
|
-
for (const element of path.node.value.elements)if (types_lib.isCallExpression(element) && types_lib.isIdentifier(element.callee, {
|
|
48585
|
-
name: 'zephyrRSbuildPlugin'
|
|
48586
|
-
})) {
|
|
48587
|
-
hasZephyrInPlugins = true;
|
|
48588
|
-
break;
|
|
48589
|
-
}
|
|
48590
|
-
if (!hasZephyrInPlugins) path.node.value.elements.push(types_lib.callExpression(types_lib.identifier('zephyrRSbuildPlugin'), []));
|
|
48591
|
-
}
|
|
48592
|
-
}
|
|
48593
|
-
});
|
|
48594
|
-
}
|
|
48595
48492
|
const TRANSFORMERS = {
|
|
48596
48493
|
addToComposePlugins: addToComposePlugins,
|
|
48597
48494
|
addToPluginsArray: addToPluginsArray,
|
|
@@ -48605,8 +48502,7 @@ const TRANSFORMERS = {
|
|
|
48605
48502
|
wrapModuleExports: wrapModuleExports,
|
|
48606
48503
|
wrapExportDefault: wrapExportDefault,
|
|
48607
48504
|
skipAlreadyWrapped: skipAlreadyWrapped,
|
|
48608
|
-
wrapExportedFunction: wrapExportedFunction
|
|
48609
|
-
addZephyrRSbuildPlugin: addZephyrRSbuildPlugin
|
|
48505
|
+
wrapExportedFunction: wrapExportedFunction
|
|
48610
48506
|
};
|
|
48611
48507
|
function normalizePathForOutput(filePath) {
|
|
48612
48508
|
return filePath.replace(/\\/g, '/');
|
|
@@ -48656,7 +48552,7 @@ function checkHasZephyr(filePath, config) {
|
|
|
48656
48552
|
}
|
|
48657
48553
|
{
|
|
48658
48554
|
const ast = parseFile(filePath);
|
|
48659
|
-
return
|
|
48555
|
+
return hasZephyrPlugin(ast);
|
|
48660
48556
|
}
|
|
48661
48557
|
} catch (error) {
|
|
48662
48558
|
console.warn(source.yellow(`Warning: Could not parse ${normalizePathForOutput(filePath)}: ${error.message}`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "with-zephyr",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.5",
|
|
4
4
|
"description": "A codemod to automatically add withZephyr plugin to bundler configurations",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/node": "^24.5.2",
|
|
39
39
|
"@rslib/core": "^0.13.3",
|
|
40
40
|
"typescript": "^5.9.2",
|
|
41
|
-
"zephyr-rsbuild-plugin": "0.0.0-canary.
|
|
41
|
+
"zephyr-rsbuild-plugin": "0.0.0-canary.5"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"zephyr",
|