@umijs/mfsu 4.0.0-rc.1 → 4.0.0-rc.2

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.
@@ -13,7 +13,7 @@ const isExternals_1 = require("./isExternals");
13
13
  const RE_NODE_MODULES = /node_modules/;
14
14
  const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
15
15
  function isUmiLocalDev(path) {
16
- return RE_UMI_LOCAL_DEV.test(path);
16
+ return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
17
17
  }
18
18
  function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
19
19
  var _a, _b;
@@ -69,7 +69,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
69
69
  isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
70
70
  }
71
71
  if (isMatch) {
72
- replaceValue = `${remoteName}/${value}`;
72
+ replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
73
73
  }
74
74
  // @ts-ignore
75
75
  const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
package/dist/dep/dep.js CHANGED
@@ -37,7 +37,7 @@ function resolve(context, path) {
37
37
  }
38
38
  class Dep {
39
39
  constructor(opts) {
40
- this.file = opts.file;
40
+ this.file = (0, utils_1.winPath)(opts.file);
41
41
  this.version = opts.version;
42
42
  this.cwd = opts.cwd;
43
43
  this.shortFile = this.file;
@@ -98,7 +98,7 @@ export * from '${this.file}';
98
98
  const dep = (0, path_1.isAbsolute)(opts.dep)
99
99
  ? opts.dep
100
100
  : (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
101
- const pkg = utils_1.pkgUp.sync({
101
+ const pkg = utils_1.pkgUp.pkgUpSync({
102
102
  cwd: dep,
103
103
  });
104
104
  (0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
@@ -299,15 +299,12 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
299
299
  `;
300
300
  }
301
301
  exports.getESBuildEntry = getESBuildEntry;
302
- function normalizeFile(file) {
303
- return file.replace(/\//g, '_');
304
- }
305
302
  function getDepModuleStr(dep) {
306
303
  return `
307
304
  "./${dep.file}": function() {
308
305
  return new Promise(resolve => {
309
- import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
310
- resolve(() => module);
306
+ import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
307
+ resolve(() => module.default || module);
311
308
  });
312
309
  })
313
310
  }
@@ -0,0 +1,2 @@
1
+ import { IEsbuildLoaderHandlerParams } from '../types';
2
+ export declare function autoCssModulesHandler(opts: IEsbuildLoaderHandlerParams): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoCssModulesHandler = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ const CSS_MODULES_QUERY = '?modules';
6
+ const QUERY_LENGTH = CSS_MODULES_QUERY.length;
7
+ function autoCssModulesHandler(opts) {
8
+ let { code } = opts;
9
+ let offset = 0;
10
+ opts.imports.forEach((i) => {
11
+ if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
12
+ // import x from './index.less'
13
+ // => import x from '
14
+ const importSegment = code.substring(i.ss + offset, i.s + offset);
15
+ // is css module
16
+ if (~importSegment.indexOf(' from')) {
17
+ code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
18
+ offset += QUERY_LENGTH;
19
+ }
20
+ }
21
+ });
22
+ return code;
23
+ }
24
+ exports.autoCssModulesHandler = autoCssModulesHandler;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function autoExportHandler(opts) {
4
4
  if (!opts.exports.length) {
5
- return `${opts.code};\nexport const __mfsu = 1;`;
5
+ return `${opts.code}\nexport const __mfsu = 1;`;
6
6
  }
7
7
  return opts.code;
8
8
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './constants';
2
+ export * from './esbuildHandlers/autoCssModules';
3
+ export { esbuildLoader } from './loader/esbuild';
2
4
  export * from './mfsu';
package/dist/index.js CHANGED
@@ -10,5 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.esbuildLoader = void 0;
13
14
  __exportStar(require("./constants"), exports);
15
+ __exportStar(require("./esbuildHandlers/autoCssModules"), exports);
16
+ // for independent use `esbuild-loader`
17
+ var esbuild_1 = require("./loader/esbuild");
18
+ Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
14
19
  __exportStar(require("./mfsu"), exports);
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ import type { IEsbuildLoaderOpts } from '../types';
3
+ declare function esbuildTranspiler(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
4
+ export default esbuildTranspiler;
5
+ export declare const esbuildLoader: string;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.esbuildLoader = void 0;
24
+ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
25
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
26
+ const path_1 = require("path");
27
+ function esbuildTranspiler(source) {
28
+ var _a;
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const done = this.async();
31
+ const options = this.getOptions();
32
+ const { handler = [], implementation } = options, otherOptions = __rest(options, ["handler", "implementation"]);
33
+ const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
34
+ const filePath = this.resourcePath;
35
+ const ext = (0, path_1.extname)(filePath).slice(1);
36
+ const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
37
+ try {
38
+ let { code, map } = yield transform(source, transformOptions);
39
+ if (handler.length) {
40
+ yield es_module_lexer_1.init;
41
+ handler.forEach((handle) => {
42
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
43
+ code = handle({ code, imports, exports, filePath });
44
+ });
45
+ }
46
+ done(null, code, map && JSON.parse(map));
47
+ }
48
+ catch (error) {
49
+ done(error);
50
+ }
51
+ });
52
+ }
53
+ exports.default = esbuildTranspiler;
54
+ exports.esbuildLoader = __filename;
package/dist/mfsu.js CHANGED
@@ -53,7 +53,7 @@ class MFSU {
53
53
  // swc don't support top-level await
54
54
  // ref: https://github.com/vercel/next.js/issues/31054
55
55
  asyncImport(content) {
56
- return `await import('${content}');`;
56
+ return `await import('${(0, utils_1.winPath)(content)}');`;
57
57
  // return `(async () => await import('${content}'))();`;
58
58
  }
59
59
  setWebpackConfig(opts) {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,16 @@
1
+ import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
1
3
  export declare enum Mode {
2
4
  development = "development",
3
5
  production = "production"
4
6
  }
7
+ export interface IEsbuildLoaderHandlerParams {
8
+ code: string;
9
+ filePath: string;
10
+ imports: readonly ImportSpecifier[];
11
+ exports: readonly string[];
12
+ }
13
+ export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
+ handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
+ implementation?: typeof import('esbuild');
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.2",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -21,15 +21,15 @@
21
21
  "dev": "pnpm build -- --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-esbuild": "4.0.0-rc.1",
25
- "@umijs/bundler-utils": "4.0.0-rc.1",
26
- "@umijs/utils": "4.0.0-rc.1"
24
+ "@umijs/bundler-esbuild": "4.0.0-rc.2",
25
+ "@umijs/bundler-utils": "4.0.0-rc.2",
26
+ "@umijs/utils": "4.0.0-rc.2",
27
+ "enhanced-resolve": "5.9.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/express": "4.17.13",
30
- "enhanced-resolve": "5.8.3",
31
31
  "mrmime": "1.0.0",
32
- "webpack": "5.64.4",
32
+ "webpack": "5.69.1",
33
33
  "webpack-virtual-modules": "0.4.3"
34
34
  },
35
35
  "publishConfig": {