@meteorjs/rspack 0.1.5 → 0.2.50

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/index.d.ts CHANGED
@@ -43,7 +43,7 @@ type MeteorEnv = Record<string, any> & {
43
43
  * @param options - Optional configuration options
44
44
  * @returns A config object with module rules configuration
45
45
  */
46
- compileWithRspack: (deps: RuleSetConditions) => Record<string, object>;
46
+ compileWithRspack: (deps: RuleSetConditions, options?: SwcLoaderOptions) => Record<string, object>;
47
47
  /**
48
48
  * Enable or disable Rspack cache config.
49
49
  * @param enabled - Whether to enable caching
@@ -61,6 +61,11 @@ type MeteorEnv = Record<string, any> & {
61
61
  * @returns A config object with SWC loader config
62
62
  */
63
63
  extendSwcConfig: (swcConfig: SwcLoaderOptions) => Record<string, object>;
64
+ /**
65
+ * Extend Rspack configs.
66
+ * @returns A config object with merged configs
67
+ */
68
+ extendConfig: (...configs: Record<string, object>[]) => Record<string, object>;
64
69
  }
65
70
 
66
71
  export type ConfigFactory = (
@@ -2,18 +2,6 @@ const path = require("path");
2
2
  const { prepareMeteorRspackConfig } = require("./meteorRspackConfigFactory");
3
3
  const { builtinModules } = require("module");
4
4
 
5
- /**
6
- * Resolve a package directory from node resolution.
7
- * @param {string} pkg
8
- * @returns {string} absolute directory of the package
9
- */
10
- function pkgDir(pkg) {
11
- const resolved = require.resolve(`${pkg}/package.json`, {
12
- paths: [process.cwd()],
13
- });
14
- return path.dirname(resolved);
15
- }
16
-
17
5
  /**
18
6
  * Wrap externals for Meteor runtime (marks deps as externals).
19
7
  * Usage: compileWithMeteor(["sharp", "vimeo", "fs"])
@@ -38,7 +26,11 @@ function compileWithMeteor(deps) {
38
26
  * @returns {Record<string, object>} `{ meteorRspackConfigX: { module: { rules: [...] } } }`
39
27
  */
40
28
  function compileWithRspack(deps, { options = {} } = {}) {
41
- const includeDirs = deps.flat().filter(Boolean).map(pkgDir);
29
+ const includeDirs = deps.flat().filter(Boolean)
30
+ .map(pkg => typeof pkg === 'string' && !pkg.includes('node_modules')
31
+ ? path.join(process.cwd(), 'node_modules', pkg)
32
+ : pkg
33
+ );
42
34
 
43
35
  return prepareMeteorRspackConfig({
44
36
  module: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteorjs/rspack",
3
- "version": "0.1.5",
3
+ "version": "0.2.50",
4
4
  "description": "Configuration logic for using Rspack in Meteor projects",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -443,13 +443,18 @@ class RequireExternalsPlugin {
443
443
 
444
444
  _ensureGlobalThisModule() {
445
445
  const block = [
446
- `/* Polyfill globalThis.module & exports */`,
447
- `if (typeof globalThis.module === 'undefined') {`,
448
- ` globalThis.module = { exports: {} };`,
446
+ `/* Polyfill globalThis.module, exports & module for legacy */`,
447
+ `if (typeof globalThis !== 'undefined') {`,
448
+ ` if (typeof globalThis.module === 'undefined') {`,
449
+ ` globalThis.module = { exports: {} };`,
450
+ ` }`,
451
+ ` if (typeof globalThis.exports === 'undefined') {`,
452
+ ` globalThis.exports = globalThis.module.exports;`,
453
+ ` }`,
454
+ `}`,
455
+ `if (typeof window.module === 'undefined') {`,
456
+ ` window.module = { exports: {} };`,
449
457
  `}`,
450
- `if (typeof globalThis.exports === 'undefined') {`,
451
- ` globalThis.exports = globalThis.module.exports;`,
452
- `}`
453
458
  ].join('\n') + '\n';
454
459
 
455
460
  let content = '';
package/rspack.config.js CHANGED
@@ -274,9 +274,9 @@ module.exports = async function (inMeteor = {}, argv = {}) {
274
274
 
275
275
  // Expose Meteor's helpers to expand Rspack configs
276
276
  Meteor.compileWithMeteor = deps => compileWithMeteor(deps);
277
- Meteor.compileWithRspack = deps =>
277
+ Meteor.compileWithRspack = (deps, options = {}) =>
278
278
  compileWithRspack(deps, {
279
- options: Meteor.swcConfigOptions,
279
+ options: mergeSplitOverlap(Meteor.swcConfigOptions, options),
280
280
  });
281
281
  Meteor.setCache = enabled =>
282
282
  setCache(
@@ -285,6 +285,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
285
285
  );
286
286
  Meteor.splitVendorChunk = () => splitVendorChunk();
287
287
  Meteor.extendSwcConfig = (customSwcConfig) => extendSwcConfig(customSwcConfig);
288
+ Meteor.extendConfig = (...configs) => mergeSplitOverlap(...configs);
288
289
 
289
290
  // Add HtmlRspackPlugin function to Meteor
290
291
  Meteor.HtmlRspackPlugin = (options = {}) => {