@meteorjs/rspack 1.1.0-beta.30 → 1.1.0-beta.31
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/.claude/settings.local.json +10 -0
- package/README.md +141 -0
- package/index.d.ts +18 -1
- package/lib/meteorRspackConfigHelpers.js +121 -0
- package/lib/meteorRspackHelpers.js +47 -3
- package/lib/swc.js +36 -6
- package/lib/test.js +8 -4
- package/package.json +1 -1
- package/plugins/RequireExtenalsPlugin.js +10 -4
- package/rspack.config.js +257 -266
- package/scripts/bump-version.js +89 -0
- package/scripts/publish-beta.sh +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @meteorjs/rspack
|
|
2
|
+
|
|
3
|
+
The default [Rspack](https://rspack.dev) configuration for Meteor applications. This package provides everything you need to bundle your Meteor app with Rspack out of the box: client and server builds, SWC transpilation, React/Blaze/Angular support, hot module replacement, asset management, and all the Meteor-specific wiring so you don't have to.
|
|
4
|
+
|
|
5
|
+
When Meteor runs with the Rspack bundler enabled, this package is what generates the underlying Rspack configuration. It detects your project setup (TypeScript, React, Blaze, Angular), sets up the right loaders and plugins, defines `Meteor.isClient`/`Meteor.isServer` and friends, configures caching, and exposes a set of helpers you can use in your own `rspack.config.js` to customize the build without breaking Meteor integration.
|
|
6
|
+
|
|
7
|
+
## What it provides
|
|
8
|
+
|
|
9
|
+
- **Dual client/server builds** with the correct targets, externals, and output paths
|
|
10
|
+
- **SWC-based transpilation** for JS/TS/JSX/TSX with automatic framework detection
|
|
11
|
+
- **React Fast Refresh** in development when React is enabled
|
|
12
|
+
- **Blaze template handling** via ignore-loader when Blaze is enabled
|
|
13
|
+
- **Persistent filesystem caching** for fast rebuilds
|
|
14
|
+
- **Asset externals and HTML generation** through custom Rspack plugins
|
|
15
|
+
- **A `defineConfig` helper** that accepts a factory function receiving Meteor environment flags and build utilities
|
|
16
|
+
- **Customizable config** via `rspack.config.js` in your project root, with safe merging that warns if you try to override reserved settings
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
[Rspack integration](https://docs.meteor.com/about/modern-build-stack/rspack-bundler-integration.html) is automatically managed by the rspack Atmosphere package.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
meteor add rspack
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
By doing this, your Meteor app will automatically serve `@meteorjs/rspack` and the required `@rspack/cli`, `@rspack/core`, among others.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
In your project's `rspack.config.js`, use the `defineConfig` helper to customize the build. The factory function receives a `env` object with Meteor environment flags and helper utilities:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const { defineConfig } = require('@meteorjs/rspack');
|
|
34
|
+
|
|
35
|
+
module.exports = defineConfig((env, argv) => {
|
|
36
|
+
// env.isClient, env.isServer, env.isDevelopment, env.isProduction
|
|
37
|
+
// env.isReactEnabled, env.isBlazeEnabled, etc.
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
// Your custom Rspack configuration here.
|
|
41
|
+
// It gets safely merged with the Meteor defaults.
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
More information is available in the official docs: [Rspack Bundler Integration](https://docs.meteor.com/about/modern-build-stack/rspack-bundler-integration.html#custom-rspack-config-js).
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
### Install dependencies
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Version bumping
|
|
57
|
+
|
|
58
|
+
Use `npm run bump` to update the version in `package.json` before publishing.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm run bump -- <major|minor|patch> [--beta]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Standard bumps** increment the version and remove any prerelease suffix:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm run bump -- patch # 1.0.1 -> 1.0.2
|
|
68
|
+
npm run bump -- minor # 1.0.1 -> 1.1.0
|
|
69
|
+
npm run bump -- major # 1.0.1 -> 2.0.0
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Beta bumps** append or increment a `-beta.N` prerelease suffix:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm run bump -- patch --beta # 1.0.1 -> 1.0.2-beta.0
|
|
76
|
+
npm run bump -- patch --beta # 1.0.2-beta.0 -> 1.0.2-beta.1
|
|
77
|
+
npm run bump -- patch --beta # 1.0.2-beta.1 -> 1.0.2-beta.2
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If you change the bump level while on a beta, the base version updates and the beta counter resets:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm run bump -- minor --beta # 1.0.2-beta.2 -> 1.1.0-beta.0
|
|
84
|
+
npm run bump -- major --beta # 1.1.0-beta.0 -> 2.0.0-beta.0
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Publishing a beta release
|
|
88
|
+
|
|
89
|
+
After bumping to a beta version, publish to the `beta` dist-tag:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm run bump -- patch --beta
|
|
93
|
+
npm run publish:beta
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Users can then install the beta with:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npm install @meteorjs/rspack@beta
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
You can pass extra flags to `npm publish` through the script:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm run publish:beta -- --dry-run
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Publishing an official release
|
|
109
|
+
|
|
110
|
+
After bumping to a stable version, publish with the default `latest` tag:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm run bump -- patch
|
|
114
|
+
npm publish
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Typical workflows
|
|
118
|
+
|
|
119
|
+
**Beta iteration**: ship multiple beta builds for the same upcoming patch:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm run bump -- patch --beta # 1.0.1 -> 1.0.2-beta.0
|
|
123
|
+
npm run publish:beta
|
|
124
|
+
# ... fix issues ...
|
|
125
|
+
npm run bump -- patch --beta # 1.0.2-beta.0 -> 1.0.2-beta.1
|
|
126
|
+
npm run publish:beta
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Promote beta to stable**: once the beta is ready, bump to the stable version and publish:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run bump -- patch # 1.0.2-beta.1 -> 1.0.3
|
|
133
|
+
npm publish
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Direct stable release**: skip the beta phase entirely:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm run bump -- minor # 1.0.1 -> 1.1.0
|
|
140
|
+
npm publish
|
|
141
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -57,10 +57,21 @@ type MeteorEnv = Record<string, any> & {
|
|
|
57
57
|
*/
|
|
58
58
|
splitVendorChunk: () => Record<string, object>;
|
|
59
59
|
/**
|
|
60
|
-
* Extend
|
|
60
|
+
* Extend the SWC loader config by smart-merging custom options on top of
|
|
61
|
+
* Meteor's defaults. Only the properties you specify are overridden;
|
|
62
|
+
* everything else is preserved.
|
|
63
|
+
* @param swcConfig - SWC loader options to merge with defaults
|
|
61
64
|
* @returns A config object with SWC loader config
|
|
62
65
|
*/
|
|
63
66
|
extendSwcConfig: (swcConfig: SwcLoaderOptions) => Record<string, object>;
|
|
67
|
+
/**
|
|
68
|
+
* Replace the SWC loader config entirely, discarding Meteor's defaults.
|
|
69
|
+
* Use this when you need full control over SWC options and don't want any
|
|
70
|
+
* automatic merging with Meteor's built-in configuration.
|
|
71
|
+
* @param swcConfig - Complete SWC loader options (replaces defaults)
|
|
72
|
+
* @returns A config object with SWC loader config
|
|
73
|
+
*/
|
|
74
|
+
replaceSwcConfig: (swcConfig: SwcLoaderOptions) => Record<string, object>;
|
|
64
75
|
/**
|
|
65
76
|
* Extend Rspack configs.
|
|
66
77
|
* @returns A config object with merged configs
|
|
@@ -75,6 +86,12 @@ type MeteorEnv = Record<string, any> & {
|
|
|
75
86
|
disablePlugins: (
|
|
76
87
|
matchers: string | RegExp | ((plugin: any, index: number) => boolean) | Array<string | RegExp | ((plugin: any, index: number) => boolean)>
|
|
77
88
|
) => Record<string, any>;
|
|
89
|
+
/**
|
|
90
|
+
* Omit `Meteor.isDevelopment` and `Meteor.isProduction` from the DefinePlugin so
|
|
91
|
+
* the bundle is not tied to a specific Meteor environment (portable / isomorphic builds).
|
|
92
|
+
* @returns A config fragment with `meteor.enablePortableBuild: true`
|
|
93
|
+
*/
|
|
94
|
+
enablePortableBuild: () => Record<string, any>;
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
export type ConfigFactory = (
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { cleanOmittedPaths } = require("./mergeRulesSplitOverlap.js");
|
|
4
|
+
const { mergeMeteorRspackFragments } = require("./meteorRspackConfigFactory.js");
|
|
5
|
+
|
|
6
|
+
// Helper function to load and process config files
|
|
7
|
+
async function loadAndProcessConfig(configPath, configType, Meteor, argv, disableWarnings) {
|
|
8
|
+
try {
|
|
9
|
+
// Load the config file
|
|
10
|
+
let config;
|
|
11
|
+
if (path.extname(configPath) === '.mjs') {
|
|
12
|
+
// For ESM modules, we need to use dynamic import
|
|
13
|
+
const fileUrl = `file://${configPath}`;
|
|
14
|
+
const module = await import(fileUrl);
|
|
15
|
+
config = module.default || module;
|
|
16
|
+
} else {
|
|
17
|
+
// For CommonJS modules, we can use require
|
|
18
|
+
config = require(configPath)?.default || require(configPath);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Process the config
|
|
22
|
+
const rawConfig = typeof config === 'function' ? config(Meteor, argv) : config;
|
|
23
|
+
const resolvedConfig = await Promise.resolve(rawConfig);
|
|
24
|
+
const userConfig = resolvedConfig && '0' in resolvedConfig ? resolvedConfig[0] : resolvedConfig;
|
|
25
|
+
|
|
26
|
+
// Define omitted paths and warning function
|
|
27
|
+
const omitPaths = [
|
|
28
|
+
"name",
|
|
29
|
+
"target",
|
|
30
|
+
"entry",
|
|
31
|
+
"output.path",
|
|
32
|
+
"output.filename",
|
|
33
|
+
...(Meteor.isServer ? ["optimization.splitChunks", "optimization.runtimeChunk"] : []),
|
|
34
|
+
].filter(Boolean);
|
|
35
|
+
|
|
36
|
+
const warningFn = path => {
|
|
37
|
+
if (disableWarnings) return;
|
|
38
|
+
console.warn(
|
|
39
|
+
`[${configType}] Ignored custom "${path}" — reserved for Meteor-Rspack integration.`,
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Clean omitted paths and merge Meteor Rspack fragments
|
|
44
|
+
let nextConfig = cleanOmittedPaths(userConfig, {
|
|
45
|
+
omitPaths,
|
|
46
|
+
warningFn,
|
|
47
|
+
});
|
|
48
|
+
nextConfig = mergeMeteorRspackFragments(nextConfig);
|
|
49
|
+
|
|
50
|
+
return nextConfig;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`Error loading ${configType} from ${configPath}:`, error);
|
|
53
|
+
if (configType === 'rspack.config.js') {
|
|
54
|
+
throw error; // Only rethrow for project config
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Loads both the user's Rspack configuration and its potential override.
|
|
62
|
+
*
|
|
63
|
+
* @param {string|undefined} projectConfigPath
|
|
64
|
+
* @param {object} Meteor
|
|
65
|
+
* @param {object} argv
|
|
66
|
+
* @returns {Promise<{ nextUserConfig: object|null, nextOverrideConfig: object|null }>}
|
|
67
|
+
*/
|
|
68
|
+
async function loadUserAndOverrideConfig(projectConfigPath, Meteor, argv) {
|
|
69
|
+
let nextUserConfig = null;
|
|
70
|
+
let nextOverrideConfig = null;
|
|
71
|
+
|
|
72
|
+
const projectDir = process.cwd();
|
|
73
|
+
const isMeteorPackageConfig = projectDir.includes("/packages/rspack");
|
|
74
|
+
|
|
75
|
+
if (projectConfigPath) {
|
|
76
|
+
const configDir = path.dirname(projectConfigPath);
|
|
77
|
+
const configFileName = path.basename(projectConfigPath);
|
|
78
|
+
const configExt = path.extname(configFileName);
|
|
79
|
+
const configNameWithoutExt = configFileName.replace(configExt, '');
|
|
80
|
+
const configNameFull = `${configNameWithoutExt}.override${configExt}`;
|
|
81
|
+
const overrideConfigPath = path.join(configDir, configNameFull);
|
|
82
|
+
|
|
83
|
+
if (fs.existsSync(overrideConfigPath)) {
|
|
84
|
+
nextOverrideConfig = await loadAndProcessConfig(
|
|
85
|
+
overrideConfigPath,
|
|
86
|
+
configNameFull,
|
|
87
|
+
Meteor,
|
|
88
|
+
argv,
|
|
89
|
+
Meteor.isAngularEnabled
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (fs.existsSync(projectConfigPath) && !isMeteorPackageConfig) {
|
|
94
|
+
// Check if there's a .mjs or .cjs version of the config file
|
|
95
|
+
const mjsConfigPath = projectConfigPath.replace(/\.js$/, '.mjs');
|
|
96
|
+
const cjsConfigPath = projectConfigPath.replace(/\.js$/, '.cjs');
|
|
97
|
+
|
|
98
|
+
let projectConfigPathToUse = projectConfigPath;
|
|
99
|
+
if (fs.existsSync(mjsConfigPath)) {
|
|
100
|
+
projectConfigPathToUse = mjsConfigPath;
|
|
101
|
+
} else if (fs.existsSync(cjsConfigPath)) {
|
|
102
|
+
projectConfigPathToUse = cjsConfigPath;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
nextUserConfig = await loadAndProcessConfig(
|
|
106
|
+
projectConfigPathToUse,
|
|
107
|
+
'rspack.config.js',
|
|
108
|
+
Meteor,
|
|
109
|
+
argv,
|
|
110
|
+
Meteor.isAngularEnabled
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { nextUserConfig, nextOverrideConfig };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = {
|
|
119
|
+
loadAndProcessConfig,
|
|
120
|
+
loadUserAndOverrideConfig,
|
|
121
|
+
};
|
|
@@ -132,10 +132,14 @@ function splitVendorChunk() {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
* Extend SWC loader config
|
|
136
|
-
*
|
|
135
|
+
* Extend SWC loader config by smart-merging custom options on top of Meteor's
|
|
136
|
+
* defaults (via `mergeSplitOverlap`). Only the properties you specify are
|
|
137
|
+
* overridden; everything else is preserved.
|
|
137
138
|
*
|
|
138
|
-
*
|
|
139
|
+
* Usage: Meteor.extendSwcConfig({ jsc: { parser: { decorators: true } } })
|
|
140
|
+
*
|
|
141
|
+
* @param {object} swcConfig - SWC loader options to merge with defaults
|
|
142
|
+
* @returns {Record<string, object>} config fragment for spreading into rspack config
|
|
139
143
|
*/
|
|
140
144
|
function extendSwcConfig(swcConfig) {
|
|
141
145
|
return prepareMeteorRspackConfig({
|
|
@@ -152,6 +156,44 @@ function extendSwcConfig(swcConfig) {
|
|
|
152
156
|
});
|
|
153
157
|
}
|
|
154
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Replace the SWC loader config entirely, discarding Meteor's defaults.
|
|
161
|
+
* Use this when you need full control over SWC options and don't want any
|
|
162
|
+
* automatic merging with Meteor's built-in configuration.
|
|
163
|
+
*
|
|
164
|
+
* Usage: Meteor.replaceSwcConfig({ jsc: { parser: { syntax: 'typescript' }, target: 'es2020' } })
|
|
165
|
+
*
|
|
166
|
+
* @param {object} swcConfig - Complete SWC loader options (replaces defaults)
|
|
167
|
+
* @returns {Record<string, object>} config fragment for spreading into rspack config
|
|
168
|
+
*/
|
|
169
|
+
function replaceSwcConfig(swcConfig) {
|
|
170
|
+
return prepareMeteorRspackConfig({
|
|
171
|
+
module: {
|
|
172
|
+
rules: [
|
|
173
|
+
{
|
|
174
|
+
test: /\.(?:[mc]?js|jsx|[mc]?ts|tsx)$/i,
|
|
175
|
+
exclude: /node_modules|\.meteor\/local/,
|
|
176
|
+
loader: 'builtin:swc-loader',
|
|
177
|
+
options: swcConfig,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Signal that `Meteor.isDevelopment` and `Meteor.isProduction` should be omitted
|
|
186
|
+
* from DefinePlugin, making the bundle portable across Meteor environments.
|
|
187
|
+
* Usage: return Meteor.enablePortableBuild() in your rspack.config.js
|
|
188
|
+
*
|
|
189
|
+
* @returns {Record<string, object>} config fragment with `meteor.enablePortableBuild: true`
|
|
190
|
+
*/
|
|
191
|
+
function enablePortableBuild() {
|
|
192
|
+
return prepareMeteorRspackConfig({
|
|
193
|
+
"meteor.enablePortableBuild": true,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
155
197
|
/**
|
|
156
198
|
* Remove plugins from a Rspack config by name, RegExp, predicate, or array of them.
|
|
157
199
|
* When using a function predicate, it receives both the plugin and its index in the plugins array.
|
|
@@ -214,7 +256,9 @@ module.exports = {
|
|
|
214
256
|
setCache,
|
|
215
257
|
splitVendorChunk,
|
|
216
258
|
extendSwcConfig,
|
|
259
|
+
replaceSwcConfig,
|
|
217
260
|
makeWebNodeBuiltinsAlias,
|
|
218
261
|
disablePlugins,
|
|
219
262
|
outputMeteorRspack,
|
|
263
|
+
enablePortableBuild,
|
|
220
264
|
};
|
package/lib/swc.js
CHANGED
|
@@ -9,11 +9,38 @@ const vm = require('vm');
|
|
|
9
9
|
function getMeteorAppSwcrc(file = '.swcrc') {
|
|
10
10
|
try {
|
|
11
11
|
const filePath = `${process.cwd()}/${file}`;
|
|
12
|
-
if (file.endsWith('.js')) {
|
|
12
|
+
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
13
13
|
let content = fs.readFileSync(filePath, 'utf-8');
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
if (file.endsWith('.ts')) {
|
|
16
|
+
try {
|
|
17
|
+
const swc = require('@swc/core');
|
|
18
|
+
const result = swc.transformSync(content, {
|
|
19
|
+
jsc: {
|
|
20
|
+
parser: {
|
|
21
|
+
syntax: 'typescript',
|
|
22
|
+
},
|
|
23
|
+
target: 'es2015',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
content = result.code;
|
|
27
|
+
} catch (swcError) {
|
|
28
|
+
content = content
|
|
29
|
+
.replace(/import\s+type\s+.*?from\s+['"][^'"]+['"];?/g, '')
|
|
30
|
+
.replace(/import\s+.*?from\s+['"][^'"]+['"];?/g, '')
|
|
31
|
+
.replace(/import\s+['"][^'"]+['"];?/g, '')
|
|
32
|
+
.replace(/export\s+default\s+/, 'module.exports = ')
|
|
33
|
+
.replace(/export\s+/g, '')
|
|
34
|
+
.replace(/:\s*\w+(\[\])?(\s*=)/g, '$2')
|
|
35
|
+
.replace(/\(([^)]*?):\s*\w+(\[\])?\)/g, '($1)')
|
|
36
|
+
.replace(/\):\s*\w+(\[\])?\s*\{/g, ') {')
|
|
37
|
+
.replace(/interface\s+\w+\s*\{[^}]*\}/g, '')
|
|
38
|
+
.replace(/type\s+\w+\s*=\s*[^;]+;/g, '')
|
|
39
|
+
.replace(/as\s+\w+(\[\])?/g, '');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
15
43
|
if (content.includes('export default')) {
|
|
16
|
-
// Transform ES module syntax to CommonJS
|
|
17
44
|
content = content.replace(/export\s+default\s+/, 'module.exports = ');
|
|
18
45
|
}
|
|
19
46
|
const script = new vm.Script(`
|
|
@@ -27,7 +54,9 @@ function getMeteorAppSwcrc(file = '.swcrc') {
|
|
|
27
54
|
})()
|
|
28
55
|
`);
|
|
29
56
|
const context = vm.createContext({ process });
|
|
30
|
-
|
|
57
|
+
const result = script.runInContext(context);
|
|
58
|
+
// Handle CJS interop wrapper (e.g. { __esModule: true, default: config })
|
|
59
|
+
return result && result.__esModule && result.default ? result.default : result;
|
|
31
60
|
} else {
|
|
32
61
|
// For .swcrc and other JSON files, parse as JSON
|
|
33
62
|
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
@@ -45,12 +74,13 @@ function getMeteorAppSwcrc(file = '.swcrc') {
|
|
|
45
74
|
function getMeteorAppSwcConfig() {
|
|
46
75
|
const hasSwcRc = fs.existsSync(`${process.cwd()}/.swcrc`);
|
|
47
76
|
const hasSwcJs = !hasSwcRc && fs.existsSync(`${process.cwd()}/swc.config.js`);
|
|
77
|
+
const hasSwcTs = !hasSwcRc && !hasSwcJs && fs.existsSync(`${process.cwd()}/swc.config.ts`);
|
|
48
78
|
|
|
49
|
-
if (!hasSwcRc && !hasSwcJs) {
|
|
79
|
+
if (!hasSwcRc && !hasSwcJs && !hasSwcTs) {
|
|
50
80
|
return undefined;
|
|
51
81
|
}
|
|
52
82
|
|
|
53
|
-
const swcFile = hasSwcJs ? 'swc.config.js' : '.swcrc';
|
|
83
|
+
const swcFile = hasSwcTs ? 'swc.config.ts' : hasSwcJs ? 'swc.config.js' : '.swcrc';
|
|
54
84
|
const config = getMeteorAppSwcrc(swcFile);
|
|
55
85
|
|
|
56
86
|
// Set baseUrl to process.cwd() if it exists
|
package/lib/test.js
CHANGED
|
@@ -2,6 +2,10 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { createIgnoreRegex, createIgnoreGlobConfig } = require("./ignore.js");
|
|
4
4
|
|
|
5
|
+
// Normalize a path to always use forward slashes (POSIX style).
|
|
6
|
+
// Module identifiers in bundled JS must use '/' regardless of OS.
|
|
7
|
+
const toPosix = (p) => p.replace(/\\/g, '/');
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* Generates eager test files dynamically
|
|
7
11
|
* @param {Object} options - Options for generating the test file
|
|
@@ -58,14 +62,14 @@ const generateEagerTestFile = ({
|
|
|
58
62
|
: "/\\.(?:test|spec)s?\\.[^.]+$/";
|
|
59
63
|
|
|
60
64
|
const content = `${
|
|
61
|
-
globalImportPath ? `import '${globalImportPath}';\n\n` : ""
|
|
65
|
+
globalImportPath ? `import '${toPosix(globalImportPath)}';\n\n` : ""
|
|
62
66
|
}${
|
|
63
67
|
excludeMeteorIgnoreRegex
|
|
64
68
|
? `const MeteorIgnoreRegex = ${excludeMeteorIgnoreRegex.toString()};`
|
|
65
69
|
: ""
|
|
66
70
|
}
|
|
67
71
|
{
|
|
68
|
-
const ctx = import.meta.webpackContext('${projectDir}', {
|
|
72
|
+
const ctx = import.meta.webpackContext('${toPosix(projectDir)}', {
|
|
69
73
|
recursive: true,
|
|
70
74
|
regExp: ${regExp},
|
|
71
75
|
exclude: ${excludeFoldersRegex.toString()},
|
|
@@ -81,9 +85,9 @@ const generateEagerTestFile = ({
|
|
|
81
85
|
}).forEach(ctx);
|
|
82
86
|
${
|
|
83
87
|
extraEntry
|
|
84
|
-
? `const extra = import.meta.webpackContext('${path.dirname(
|
|
88
|
+
? `const extra = import.meta.webpackContext('${toPosix(path.dirname(
|
|
85
89
|
extraEntry
|
|
86
|
-
)}', {
|
|
90
|
+
))}', {
|
|
87
91
|
recursive: false,
|
|
88
92
|
regExp: ${new RegExp(`${path.basename(extraEntry)}$`).toString()},
|
|
89
93
|
mode: 'eager',
|
package/package.json
CHANGED
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
|
|
13
|
+
// Normalize a path to always use forward slashes (POSIX style).
|
|
14
|
+
// Module identifiers in bundled JS must use '/' regardless of OS.
|
|
15
|
+
const toPosix = (p) => p.replace(/\\/g, '/');
|
|
16
|
+
|
|
13
17
|
class RequireExternalsPlugin {
|
|
14
18
|
constructor({
|
|
15
19
|
filePath,
|
|
@@ -46,7 +50,7 @@ class RequireExternalsPlugin {
|
|
|
46
50
|
// Prepare paths
|
|
47
51
|
this.filePath = path.resolve(process.cwd(), filePath);
|
|
48
52
|
this.backRoot = '../'.repeat(
|
|
49
|
-
filePath.replace(
|
|
53
|
+
filePath.replace(/^\.?[/\\]+/, '').split(/[/\\]/).length - 1
|
|
50
54
|
);
|
|
51
55
|
|
|
52
56
|
// Initialize funcCount based on existing helpers in the file
|
|
@@ -96,14 +100,16 @@ class RequireExternalsPlugin {
|
|
|
96
100
|
pkg &&
|
|
97
101
|
(path.isAbsolute(pkg) ||
|
|
98
102
|
pkg.startsWith('./') ||
|
|
103
|
+
pkg.startsWith('.\\') ||
|
|
99
104
|
pkg.startsWith('../') ||
|
|
105
|
+
pkg.startsWith('..\\') ||
|
|
100
106
|
!!depInfo.ext)
|
|
101
107
|
) {
|
|
102
108
|
const module = this.externalsMeta.get(pkg);
|
|
103
109
|
if (module) {
|
|
104
|
-
return `${this.backRoot}${module.relativeRequest}`;
|
|
110
|
+
return `${this.backRoot}${toPosix(module.relativeRequest)}`;
|
|
105
111
|
}
|
|
106
|
-
return `${this.backRoot}${name}`;
|
|
112
|
+
return `${this.backRoot}${toPosix(name)}`;
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
return pkg;
|
|
@@ -132,7 +138,7 @@ class RequireExternalsPlugin {
|
|
|
132
138
|
this.externalsMeta.set(externalRequest, {
|
|
133
139
|
originalRequest: request,
|
|
134
140
|
externalRequest,
|
|
135
|
-
relativeRequest: path.join(relContext, request),
|
|
141
|
+
relativeRequest: toPosix(path.join(relContext, request)),
|
|
136
142
|
});
|
|
137
143
|
|
|
138
144
|
// tell Rspack "don't bundle this, import it at runtime"
|