@modern-js/module-tools 2.35.0 → 2.36.0
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/compiled/postcss-nesting/index.js +2 -2
- package/compiled/postcss-nesting/package.json +1 -1
- package/dist/build.js +43 -16
- package/dist/builder/build.d.ts +1 -10
- package/dist/builder/build.js +96 -208
- package/dist/builder/clear.d.ts +1 -4
- package/dist/builder/clear.js +32 -28
- package/dist/builder/copy.js +79 -64
- package/dist/builder/dts/index.js +27 -19
- package/dist/builder/dts/rollup.d.ts +6 -14
- package/dist/builder/dts/rollup.js +60 -37
- package/dist/builder/dts/tsc.d.ts +3 -2
- package/dist/builder/dts/tsc.js +50 -37
- package/dist/builder/esbuild/adapter.d.ts +3 -0
- package/dist/builder/esbuild/adapter.js +275 -0
- package/dist/builder/esbuild/hook.d.ts +4 -0
- package/dist/builder/esbuild/hook.js +103 -0
- package/dist/builder/esbuild/index.d.ts +35 -0
- package/dist/builder/esbuild/index.js +268 -0
- package/dist/builder/esbuild/resolve.d.ts +17 -0
- package/dist/builder/esbuild/resolve.js +125 -0
- package/dist/builder/esbuild/sourcemap.d.ts +16 -0
- package/dist/builder/esbuild/sourcemap.js +86 -0
- package/dist/builder/esbuild/transform.d.ts +7 -0
- package/dist/builder/esbuild/transform.js +45 -0
- package/dist/builder/esbuild/watch.d.ts +2 -0
- package/dist/builder/esbuild/watch.js +115 -0
- package/dist/builder/esbuild/write-file.d.ts +2 -0
- package/dist/builder/esbuild/write-file.js +89 -0
- package/dist/builder/feature/asset.d.ts +19 -0
- package/dist/builder/feature/asset.js +149 -0
- package/dist/builder/feature/format-cjs.d.ts +5 -0
- package/dist/builder/feature/format-cjs.js +53 -0
- package/dist/builder/feature/index.d.ts +2 -0
- package/dist/builder/feature/index.js +74 -0
- package/dist/builder/feature/json.d.ts +5 -0
- package/dist/builder/feature/json.js +47 -0
- package/dist/builder/feature/redirect.d.ts +5 -0
- package/dist/builder/feature/redirect.js +217 -0
- package/dist/builder/feature/style/index.d.ts +5 -0
- package/dist/builder/feature/style/index.js +94 -0
- package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
- package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
- package/dist/builder/feature/style/lessRender.d.ts +2 -0
- package/dist/builder/feature/style/lessRender.js +64 -0
- package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
- package/dist/builder/feature/style/postcssTransformer.js +95 -0
- package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
- package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
- package/dist/builder/feature/style/sassRender.d.ts +2 -0
- package/dist/builder/feature/style/sassRender.js +85 -0
- package/dist/builder/feature/style/transformStyle.d.ts +13 -0
- package/dist/builder/feature/style/transformStyle.js +101 -0
- package/dist/builder/feature/style/utils.d.ts +18 -0
- package/dist/builder/feature/style/utils.js +124 -0
- package/dist/builder/feature/swc.d.ts +9 -0
- package/dist/builder/feature/swc.js +170 -0
- package/dist/builder/feature/terser.d.ts +5 -0
- package/dist/builder/feature/terser.js +83 -0
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +59 -28
- package/dist/builder/platform.js +38 -23
- package/dist/cli.js +58 -29
- package/dist/command.js +62 -38
- package/dist/config/defineConfig.js +25 -17
- package/dist/config/legacySchema.js +35 -32
- package/dist/config/merge.d.ts +1 -0
- package/dist/config/merge.js +69 -36
- package/dist/config/normalize.d.ts +1 -0
- package/dist/config/normalize.js +63 -46
- package/dist/config/schema.d.ts +48 -0
- package/dist/config/schema.js +53 -34
- package/dist/config/transformLegacyConfig.js +67 -61
- package/dist/config/valid.d.ts +2 -2
- package/dist/config/valid.js +44 -21
- package/dist/constants/build.d.ts +5 -1
- package/dist/constants/build.js +88 -46
- package/dist/constants/color.js +27 -20
- package/dist/constants/dts.js +27 -20
- package/dist/constants/file.d.ts +2 -2
- package/dist/constants/file.js +48 -25
- package/dist/constants/legacy-preset.js +45 -32
- package/dist/constants/loader.d.ts +2 -0
- package/dist/constants/loader.js +53 -0
- package/dist/constants/log.d.ts +0 -8
- package/dist/constants/log.js +27 -41
- package/dist/constants/preset.js +55 -62
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +37 -0
- package/dist/dev.js +42 -25
- package/dist/error.js +49 -42
- package/dist/hooks/build.d.ts +1 -2
- package/dist/hooks/build.js +36 -28
- package/dist/hooks/dev.js +32 -17
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +31 -16
- package/dist/hooks/misc.d.ts +5 -2
- package/dist/hooks/misc.js +31 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +39 -32
- package/dist/locale/en.js +32 -17
- package/dist/locale/index.d.ts +2 -1
- package/dist/locale/index.js +31 -24
- package/dist/locale/zh.js +32 -17
- package/dist/plugins.js +28 -13
- package/dist/types/color.js +15 -5
- package/dist/types/command.d.ts +3 -3
- package/dist/types/command.js +15 -5
- package/dist/types/config/copy.js +15 -5
- package/dist/types/config/dev.js +15 -5
- package/dist/types/config/index.d.ts +87 -52
- package/dist/types/config/index.js +24 -6
- package/dist/types/config/style.d.ts +58 -6
- package/dist/types/config/style.js +15 -5
- package/dist/types/context.js +15 -5
- package/dist/types/dts.d.ts +14 -3
- package/dist/types/dts.js +15 -5
- package/dist/types/esbuild.d.ts +107 -0
- package/dist/types/esbuild.js +32 -0
- package/dist/types/hooks.js +15 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +32 -11
- package/dist/types/legacyConfig/index.js +15 -5
- package/dist/types/legacyConfig/output.d.ts +4 -4
- package/dist/types/legacyConfig/output.js +15 -5
- package/dist/types/legacyConfig/source.js +15 -5
- package/dist/types/legacyConfig/tools.js +15 -5
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.js +50 -0
- package/dist/utils/builder.d.ts +10 -14
- package/dist/utils/builder.js +59 -59
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +25 -17
- package/dist/utils/dts.d.ts +26 -9
- package/dist/utils/dts.js +100 -66
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +31 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/input.js +47 -24
- package/dist/utils/log.d.ts +1 -2
- package/dist/utils/log.js +36 -20
- package/dist/utils/map.d.ts +13 -0
- package/dist/utils/map.js +58 -0
- package/dist/utils/onExit.js +35 -11
- package/dist/utils/print.d.ts +2 -2
- package/dist/utils/print.js +52 -49
- package/dist/utils/style.d.ts +5 -23
- package/dist/utils/style.js +63 -43
- package/dist/utils/tspath.js +114 -0
- package/package.json +64 -50
- package/vitest.config.ts +20 -0
- package/dist/build.js.map +0 -1
- package/dist/builder/build.js.map +0 -1
- package/dist/builder/clear.js.map +0 -1
- package/dist/builder/copy.js.map +0 -1
- package/dist/builder/dts/index.js.map +0 -1
- package/dist/builder/dts/rollup.js.map +0 -1
- package/dist/builder/dts/tsc.js.map +0 -1
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/platform.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/command.js.map +0 -1
- package/dist/config/defineConfig.js.map +0 -1
- package/dist/config/legacySchema.js.map +0 -1
- package/dist/config/merge.js.map +0 -1
- package/dist/config/normalize.js.map +0 -1
- package/dist/config/schema.js.map +0 -1
- package/dist/config/transformLegacyConfig.js.map +0 -1
- package/dist/config/valid.js.map +0 -1
- package/dist/constants/build.js.map +0 -1
- package/dist/constants/color.js.map +0 -1
- package/dist/constants/dts.js.map +0 -1
- package/dist/constants/file.js.map +0 -1
- package/dist/constants/legacy-preset.js.map +0 -1
- package/dist/constants/log.js.map +0 -1
- package/dist/constants/preset.js.map +0 -1
- package/dist/dev.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/hooks/build.js.map +0 -1
- package/dist/hooks/dev.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/misc.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locale/en.js.map +0 -1
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/zh.js.map +0 -1
- package/dist/plugins.js.map +0 -1
- package/dist/types/color.js.map +0 -1
- package/dist/types/command.js.map +0 -1
- package/dist/types/config/copy.js.map +0 -1
- package/dist/types/config/dev.js.map +0 -1
- package/dist/types/config/index.js.map +0 -1
- package/dist/types/config/style.js.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/dts.js.map +0 -1
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/legacyConfig/index.js.map +0 -1
- package/dist/types/legacyConfig/output.js.map +0 -1
- package/dist/types/legacyConfig/source.js.map +0 -1
- package/dist/types/legacyConfig/tools.js.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.js +0 -4
- package/dist/utils/builder.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/context.d.ts +0 -7
- package/dist/utils/context.js +0 -23
- package/dist/utils/context.js.map +0 -1
- package/dist/utils/dts.js.map +0 -1
- package/dist/utils/input.js.map +0 -1
- package/dist/utils/language.d.ts +0 -1
- package/dist/utils/language.js +0 -22
- package/dist/utils/language.js.map +0 -1
- package/dist/utils/libuild-plugin.d.ts +0 -3
- package/dist/utils/libuild-plugin.js +0 -31
- package/dist/utils/libuild-plugin.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/onExit.js.map +0 -1
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +0 -19
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/style.js.map +0 -1
- package/dist/utils/tspathsTransform.js +0 -91
- package/dist/utils/tspathsTransform.js.map +0 -1
- /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
package/dist/utils/language.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "initLocalLanguage", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return initLocalLanguage;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
-
const initLocalLanguage = async () => {
|
|
13
|
-
const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../locale")));
|
|
14
|
-
const { getLocaleLanguage } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/plugin-i18n/language-detector")));
|
|
15
|
-
const locale = getLocaleLanguage();
|
|
16
|
-
local.i18n.changeLanguage({
|
|
17
|
-
locale
|
|
18
|
-
});
|
|
19
|
-
return local;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=language.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAAaA;;;WAAAA;;;;AAAN,MAAMA,oBAAoB;AAC/B,QAAMC,QAAQ,MAAM,iFAAO;AAC3B,QAAM,EAAEC,kBAAiB,IAAK,MAAM,iFAClC;AAEF,QAAMC,SAASD;AACfD,QAAMG,KAAKC,eAAe;IAAEF;EAAO;AACnC,SAAOF;AACT;","names":["initLocalLanguage","local","getLocaleLanguage","locale","i18n","changeLanguage"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/language.ts"],"sourcesContent":["export const initLocalLanguage = async () => {\n const local = await import('../locale');\n const { getLocaleLanguage } = await import(\n '@modern-js/plugin-i18n/language-detector'\n );\n const locale = getLocaleLanguage();\n local.i18n.changeLanguage({ locale });\n return local;\n};\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "watchPlugin", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return watchPlugin;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
-
const _logger = require("@modern-js/utils/logger");
|
|
13
|
-
const watchPlugin = (api, config) => {
|
|
14
|
-
return {
|
|
15
|
-
name: "watch-plugin",
|
|
16
|
-
apply(compiler) {
|
|
17
|
-
compiler.hooks.watchChange.tap("watch-plugin", async () => {
|
|
18
|
-
const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./log")));
|
|
19
|
-
const { SectionTitleStatus } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/log")));
|
|
20
|
-
const titleText = `[${config.buildType === "bundle" ? "Bundle" : "Bundleless"}:${config.format}_${config.target}]`;
|
|
21
|
-
_logger.logger.info(await watchSectionTitle(titleText, SectionTitleStatus.Log));
|
|
22
|
-
const runner = api.useHookRunners();
|
|
23
|
-
runner.buildWatchJs({
|
|
24
|
-
buildConfig: config
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=libuild-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAIaA;;;WAAAA;;;;wBAJU;AAIhB,MAAMA,cAAc,CACzBC,KACAC;AAEA,SAAO;IACLC,MAAM;IACNC,MAAMC,UAAQ;AACZA,eAASC,MAAMC,YAAYC,IAAI,gBAAgB;AAC7C,cAAM,EAAEC,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,cAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,cAAMC,YAAY,IAChBT,OAAOU,cAAc,WAAW,WAAW,gBACzCV,OAAOW,UAAUX,OAAOY;AAE5BC,uBAAOC,KAAK,MAAMP,kBAAkBE,WAAWD,mBAAmBO,GAAG;AAErE,cAAMC,SAASjB,IAAIkB,eAAc;AACjCD,eAAOE,aAAa;UAAEC,aAAanB;QAAO;MAC5C;IACF;EACF;AACF;","names":["watchPlugin","api","config","name","apply","compiler","hooks","watchChange","tap","watchSectionTitle","SectionTitleStatus","titleText","buildType","format","target","logger","info","Log","runner","useHookRunners","buildWatchJs","buildConfig"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/libuild-plugin.ts"],"sourcesContent":["import { logger } from '@modern-js/utils/logger';\nimport type { LibuildPlugin } from '@modern-js/libuild';\nimport type { BaseBuildConfig, PluginAPI, ModuleTools } from '../types';\n\nexport const watchPlugin = (\n api: PluginAPI<ModuleTools>,\n config: BaseBuildConfig,\n): LibuildPlugin => {\n return {\n name: 'watch-plugin',\n apply(compiler) {\n compiler.hooks.watchChange.tap('watch-plugin', async () => {\n const { watchSectionTitle } = await import('./log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n config.buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }:${config.format}_${config.target}]`;\n\n logger.info(await watchSectionTitle(titleText, SectionTitleStatus.Log));\n\n const runner = api.useHookRunners();\n runner.buildWatchJs({ buildConfig: config });\n });\n },\n };\n};\n"]}
|
package/dist/utils/log.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAEaA;;;WAAAA;;;;qBAFsB;AAE5B,MAAMA,oBAAoB,OAC/BC,KACAC,QACAC;AAEA,QAAM,EAAEC,MAAK,IAAK,MAAM,iFAAO;AAC/B,MAAIF,WAAWG,wBAAmBC,SAAS;AACzC,WAAO,GAAGF,MAAMG,KAAKN,QAAQG,MAAMI,MAAM;EAC3C,WAAWN,WAAWG,wBAAmBI,MAAM;AAC7C,WAAO,GAAGL,MAAMG,KAAKN,QAAQG,MAAMM,IAAI;EACzC;AAEA,SAAO,GAAGN,MAAMG,KAAKN,QAAQE,YAAYA,YAAY;AACvD;","names":["watchSectionTitle","str","status","detailLog","chalk","SectionTitleStatus","Success","gray","green","Fail","red"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/log.ts"],"sourcesContent":["import { SectionTitleStatus } from '../constants/log';\n\nexport const watchSectionTitle = async (\n str: string,\n status: SectionTitleStatus,\n detailLog?: string,\n) => {\n const { chalk } = await import('@modern-js/utils');\n if (status === SectionTitleStatus.Success) {\n return `${chalk.gray(str)} ${chalk.green('Successful')}`;\n } else if (status === SectionTitleStatus.Fail) {\n return `${chalk.gray(str)} ${chalk.red('Build Failed')}`;\n }\n\n return `${chalk.gray(str)} ${detailLog ? detailLog : 'Log:'}`;\n};\n"]}
|
package/dist/utils/onExit.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAAaA;;;WAAAA;;;;AAAN,MAAMA,kBAAkB,OAAOC;AACpC,QAAM,EAAEC,SAASC,OAAM,IAAK,MAAM,iFAAO;AAEzCA,SAAO,OAAMC;AACX,QAAIA,SAAS,GAAG;AACd;IACF;AAEA,UAAMH;EACR;AACF;","names":["addExitListener","fn","default","onExit","code"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/onExit.ts"],"sourcesContent":["export const addExitListener = async (fn: () => Promise<void>) => {\n const { default: onExit } = await import('../../compiled/signal-exit');\n\n onExit(async code => {\n if (code === 0) {\n return;\n }\n\n await fn();\n });\n};\n"]}
|
package/dist/utils/path.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getCompiledPath: (packageName: string) => Promise<string>;
|
package/dist/utils/path.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "getCompiledPath", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return getCompiledPath;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
-
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
14
|
-
const getCompiledPath = async (packageName) => {
|
|
15
|
-
const { slash } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
16
|
-
return slash(_path.default.join(__dirname, "../../compiled", packageName));
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=path.js.map
|
package/dist/utils/path.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAEaA;;;WAAAA;;;;;iEAFI;AAEV,MAAMA,kBAAkB,OAAOC;AACpC,QAAM,EAAEC,MAAK,IAAK,MAAM,iFAAO;AAC/B,SAAOA,MAAMC,cAAKC,KAAKC,WAAW,kBAAkBJ;AACtD;","names":["getCompiledPath","packageName","slash","path","join","__dirname"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/path.ts"],"sourcesContent":["import path from 'path';\n\nexport const getCompiledPath = async (packageName: string) => {\n const { slash } = await import('@modern-js/utils');\n return slash(path.join(__dirname, '../../compiled', packageName));\n};\n"]}
|
package/dist/utils/print.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"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","names":["bundleFiles","bundlelessFiles","addOutputChunk","addRollupChunk","addDtsFiles","printFileSize","printSucceed","outputChunk","appDirectory","isBundle","files","Array","from","map","val","path","chunk","name","relative","size","contents","length","push","rollupOutput","distDir","output","o","resolve","fileName","code","fastGlob","slash","stats","file","printBundlelessInfo","printBundleFiles","totalDuration","time","chalk","cyan","logger","info","buildSuccessText","prettyBytes","bytes","unit","exp","Math","floor","log","pow","toFixed","longestFileLength","reduce","max","str","reportFile1LineText","headerRow","repeat","reportFile2LineText","bold","green","forEach","infoRow","count","totalSize","total"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/print.ts"],"sourcesContent":["import { relative, resolve } from 'path';\nimport type { ILibuilder } from '@modern-js/libuild';\nimport { chalk, logger, fastGlob, slash } from '@modern-js/utils';\nimport type {\n RollupOutput,\n OutputChunk,\n} from '../../compiled/rollup/types/rollup';\nimport {\n buildSuccessText,\n reportFile1LineText,\n reportFile2LineText,\n} from '../constants/log';\n\ntype Files = {\n name: string;\n size: number;\n};\n\nexport const bundleFiles: Files[] = [];\n\nexport const bundlelessFiles: Files[] = [];\n\nexport const addOutputChunk = (\n outputChunk: ILibuilder['outputChunk'],\n appDirectory: string,\n isBundle: boolean,\n) => {\n const files = Array.from(outputChunk).map(val => {\n const [path, chunk] = val;\n return {\n name: relative(appDirectory, path),\n size: chunk.contents.length,\n };\n });\n if (isBundle) {\n bundleFiles.push(...files);\n } else {\n bundlelessFiles.push(...files);\n }\n};\n\nexport const addRollupChunk = (\n rollupOutput: RollupOutput,\n appDirectory: string,\n distDir: string,\n) => {\n const { output } = rollupOutput;\n bundleFiles.push(\n ...output.map(o => {\n return {\n name: relative(appDirectory, resolve(distDir, o.fileName)),\n // only d.ts, is outputChunk not outputAsset\n size: (o as OutputChunk).code.length,\n };\n }),\n );\n};\n\nexport const addDtsFiles = async (distDir: string, appDirectory: string) => {\n const files = await fastGlob(`${slash(distDir)}/**/*.d.ts`, {\n stats: true,\n });\n bundlelessFiles.push(\n ...files.map(file => {\n return {\n name: relative(appDirectory, file.path),\n size: file.stats.size,\n };\n }),\n );\n};\n\nexport const printFileSize = () => {\n printBundlelessInfo();\n printBundleFiles();\n};\n\nexport const printSucceed = (totalDuration: number) => {\n const time = chalk.cyan(`${totalDuration / 1000}s`);\n logger.info(`${buildSuccessText} in ${time}`);\n};\n\nconst prettyBytes = (bytes: number) => {\n if (bytes === 0) {\n return '0 B';\n }\n const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const exp = Math.floor(Math.log(bytes) / Math.log(1024));\n return `${(bytes / Math.pow(1024, exp)).toFixed(2)} ${unit[exp]}`;\n};\n\nconst printBundleFiles = () => {\n if (bundleFiles.length === 0) {\n return;\n }\n const longestFileLength = bundleFiles.reduce(\n (max, str) => Math.max(max, str.name.length),\n reportFile1LineText.length,\n );\n\n logger.info(`Bundle generated ${bundleFiles.length} files\\n`);\n\n const headerRow =\n reportFile1LineText +\n ' '.repeat(longestFileLength - 10) +\n reportFile2LineText;\n logger.log(chalk.bold(chalk.green(headerRow)));\n\n bundleFiles.forEach(({ name, size }) => {\n const infoRow = `${name}${' '.repeat(\n longestFileLength - name.length + 2,\n )}${prettyBytes(size)}`;\n logger.log(infoRow);\n });\n};\n\nconst printBundlelessInfo = () => {\n if (bundlelessFiles.length === 0) {\n return;\n }\n\n const count = bundlelessFiles.length;\n const totalSize = bundlelessFiles.reduce((total, file) => {\n return total + file.size;\n }, 0);\n const info = `Bundleless generated ${count} files, the total size is ${chalk.cyan(\n prettyBytes(totalSize),\n )}`;\n logger.info(info);\n};\n"]}
|
package/dist/utils/style.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAWaA,eAAa;WAAbA;;EAYAC,eAAa;WAAbA;;EAWAC,kBAAgB;WAAhBA;;EA6CAC,gBAAc;WAAdA;;;uBA7EqB;sBAOF;AAEzB,MAAMH,gBAAgB,OAAOI;MAMhCA;AALF,QAAMC,iBAAgBC,6BACpB;IACEC,aAAa;MAAEC,mBAAmB;IAAK;IACvCC,gBAAgB,OAAMC,0BAAgB;EACxC,KACAN,qFAAQO,WAAK,QAAbP,kDAAeQ,SAAQ,CAAC;AAG1B,SAAOP;AACT;AAEO,MAAMJ,gBAAgB,OAAOG;MAKhCA;AAJF,QAAMC,iBAAgBC,6BACpB;IACEG,gBAAgB,OAAMC,0BAAgB;EACxC,KACAN,qFAAQO,WAAK,QAAbP,kDAAeS,SAAQ,CAAC;AAG1B,SAAOR;AACT;AAEO,MAAMH,mBAAmB,OAAOE;MAmCnCA;AAlCF,QAAMU,eAAiC;AAEvC,QAAMC,QAAQ;IACZC,WAAWC,SAA0C;AACnD,UAAIC,MAAMC,QAAQF,UAAU;AAC1BH,qBAAaM,KAAI,GAAIH;MACvB,OAAO;AACLH,qBAAaM,KAAKH;MACpB;IACF;EACF;AAEA,QAAMI,uBAAuBjB,OAAOkB,WAAW;AAC/C,QAAMC,0BAA0B,YAAY;IAC1CC,QAAQ,OAAMd,0BAAgB;IAC9Bc,QAAQ,OAAMd,0BAAgB;IAC9Bc,QAAQ,OAAMd,0BAAgB;IAC9Bc,QAAQ,OAAMd,0BAAgB;;AAGhC,QAAMe,gBAAenB,6BAInB;;;IAGEW,SAAS;SACHI,uBAAuB,MAAME,4BAA4B;MAC7DC,QAAQ,OAAMd,0BAAgB;MAC9Bc,QAAQ,OAAMd,0BAAgB;MAC9Bc,QAAQ,OAAMd,0BAAgB;MAC9BgB,OAAOC;EACX,KACAvB,qFAAQO,WAAK,QAAbP,kDAAewB,YAAW,CAAC,GAC3Bb;AAEF,MAAID,aAAae,QAAQ;AACvBJ,iBAAaR,QAASG,KAAI,GAAIN;EAChC;AAEA,SAAOW;AACT;AAEO,MAAMtB,iBAAiB,OAAOC;AACnC,QAAM0B,gBAAgB,MAAM5B,iBAAiBE;AAC7C,QAAM2B,aAAa,MAAM/B,cAAcI;AACvC,QAAM4B,aAAa,MAAM/B,cAAcG;AACvC,SAAO;IACLQ,MAAMmB;IACNlB,MAAMmB;IACNJ,SAASE;EACX;AACF;","names":["getLessConfig","getSassConfig","getPostcssConfig","getStyleConfig","config","mergedOptions","applyOptionsChain","lessOptions","javascriptEnabled","implementation","getCompiledPath","style","less","sass","extraPlugins","utils","addPlugins","plugins","Array","isArray","push","targetLegacyBrowsers","target","getLegacyPostCSSPlugins","require","mergedConfig","filter","Boolean","postcss","length","postcssConfig","lessConfig","sassConfig"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/style.ts"],"sourcesContent":["import type { AcceptedPlugin } from 'postcss';\nimport type { PostcssOptions } from '@modern-js/libuild';\nimport { applyOptionsChain } from '@modern-js/utils';\nimport type {\n PartialBaseBuildConfig,\n PostCSSConfigUtils,\n LessOptions,\n SassOptions,\n} from '../types';\nimport { getCompiledPath } from './path';\n\nexport const getLessConfig = async (config: PartialBaseBuildConfig) => {\n const mergedOptions = applyOptionsChain<LessOptions, never>(\n {\n lessOptions: { javascriptEnabled: true },\n implementation: await getCompiledPath('less'),\n },\n config?.style?.less || {},\n );\n\n return mergedOptions;\n};\n\nexport const getSassConfig = async (config: PartialBaseBuildConfig) => {\n const mergedOptions = applyOptionsChain<SassOptions, never>(\n {\n implementation: await getCompiledPath('sass'),\n },\n config?.style?.sass || {},\n );\n\n return mergedOptions;\n};\n\nexport const getPostcssConfig = async (config: PartialBaseBuildConfig) => {\n const extraPlugins: AcceptedPlugin[] = [];\n\n const utils = {\n addPlugins(plugins: AcceptedPlugin | AcceptedPlugin[]) {\n if (Array.isArray(plugins)) {\n extraPlugins.push(...plugins);\n } else {\n extraPlugins.push(plugins);\n }\n },\n };\n\n const targetLegacyBrowsers = config.target === 'es5';\n const getLegacyPostCSSPlugins = async () => [\n require(await getCompiledPath('postcss-custom-properties')),\n require(await getCompiledPath('postcss-initial')),\n require(await getCompiledPath('postcss-page-break')),\n require(await getCompiledPath('postcss-font-variant')),\n ];\n\n const mergedConfig = applyOptionsChain<\n PostcssOptions & { $$tools?: string },\n PostCSSConfigUtils\n >(\n {\n // TODO: when schema support redefine\n // $$tools: 'module-tools',\n plugins: [\n ...(targetLegacyBrowsers ? await getLegacyPostCSSPlugins() : []),\n require(await getCompiledPath('postcss-flexbugs-fixes')),\n require(await getCompiledPath('postcss-media-minmax')),\n require(await getCompiledPath('postcss-nesting')),\n ].filter(Boolean),\n },\n config?.style?.postcss || {},\n utils,\n );\n if (extraPlugins.length) {\n mergedConfig.plugins!.push(...extraPlugins);\n }\n\n return mergedConfig;\n};\n\nexport const getStyleConfig = async (config: PartialBaseBuildConfig) => {\n const postcssConfig = await getPostcssConfig(config);\n const lessConfig = await getLessConfig(config);\n const sassConfig = await getSassConfig(config);\n return {\n less: lessConfig,\n sass: sassConfig,\n postcss: postcssConfig,\n };\n};\n"]}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "transformDtsAlias", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return transformDtsAlias;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
-
const _path = /* @__PURE__ */ _interop_require_wildcard._(require("path"));
|
|
14
|
-
const _tsconfigpaths = require("@modern-js/utils/tsconfig-paths");
|
|
15
|
-
const _utils = require("@modern-js/utils");
|
|
16
|
-
const _parser = /* @__PURE__ */ _interop_require_wildcard._(require("@babel/parser"));
|
|
17
|
-
const _generator = /* @__PURE__ */ _interop_require_default._(require("@babel/generator"));
|
|
18
|
-
const _types = /* @__PURE__ */ _interop_require_wildcard._(require("@babel/types"));
|
|
19
|
-
const _traverse = /* @__PURE__ */ _interop_require_default._(require("@babel/traverse"));
|
|
20
|
-
const _file = require("../constants/file");
|
|
21
|
-
function mapPathString(nodePath, { filename, baseUrl, paths }) {
|
|
22
|
-
if (!_types.isStringLiteral(nodePath)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const sourcePath = nodePath.node.value;
|
|
26
|
-
const currentFile = filename;
|
|
27
|
-
const matchPath = (0, _tsconfigpaths.createMatchPath)(baseUrl, paths, [
|
|
28
|
-
"index"
|
|
29
|
-
]);
|
|
30
|
-
const result = matchPath(sourcePath, (packageJsonPath) => {
|
|
31
|
-
if (!_utils.fs.existsSync(packageJsonPath)) {
|
|
32
|
-
return void 0;
|
|
33
|
-
}
|
|
34
|
-
return _utils.fs.readJSONSync(packageJsonPath);
|
|
35
|
-
}, (filePath) => _utils.fs.existsSync(filePath), _file.dtsAliasExts);
|
|
36
|
-
if (result) {
|
|
37
|
-
const relativePath = _path.relative(_path.dirname(currentFile), _path.dirname(result));
|
|
38
|
-
const fileName = _path.basename(result);
|
|
39
|
-
const filePath = _path.normalize(`${relativePath.length === 0 ? "." : relativePath}/${fileName}`);
|
|
40
|
-
const replaceString = filePath.startsWith(".") ? filePath : `./${filePath}`;
|
|
41
|
-
nodePath.replaceWith(_types.stringLiteral(replaceString));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const transformImport = (option) => (nodePath) => {
|
|
45
|
-
mapPathString(nodePath.get("source"), option);
|
|
46
|
-
};
|
|
47
|
-
const transformExport = (option) => (nodePath) => {
|
|
48
|
-
mapPathString(nodePath.get("source"), option);
|
|
49
|
-
};
|
|
50
|
-
const transformSingleFileAlias = ({ filename, baseUrl, paths }) => {
|
|
51
|
-
const sourceCode = _utils.fs.readFileSync(filename, "utf-8");
|
|
52
|
-
const ast = _parser.parse(sourceCode, {
|
|
53
|
-
sourceType: "module",
|
|
54
|
-
errorRecovery: true,
|
|
55
|
-
plugins: [
|
|
56
|
-
"typescript"
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
(0, _traverse.default)(ast, {
|
|
60
|
-
// d.ts file content not have callExpression which can be parsed;
|
|
61
|
-
// CallExpression: transformCall({ filename, baseUrl, paths }) as any,
|
|
62
|
-
ImportDeclaration: transformImport({
|
|
63
|
-
filename,
|
|
64
|
-
baseUrl,
|
|
65
|
-
paths
|
|
66
|
-
}),
|
|
67
|
-
ExportDeclaration: transformExport({
|
|
68
|
-
filename,
|
|
69
|
-
baseUrl,
|
|
70
|
-
paths
|
|
71
|
-
})
|
|
72
|
-
});
|
|
73
|
-
return (0, _generator.default)(ast).code;
|
|
74
|
-
};
|
|
75
|
-
const transformDtsAlias = (option) => {
|
|
76
|
-
const { filenames = [], baseUrl, paths } = option;
|
|
77
|
-
const transformResult = [];
|
|
78
|
-
for (const filename of filenames) {
|
|
79
|
-
transformResult.push({
|
|
80
|
-
path: filename,
|
|
81
|
-
content: transformSingleFileAlias({
|
|
82
|
-
filename,
|
|
83
|
-
baseUrl,
|
|
84
|
-
paths
|
|
85
|
-
})
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return transformResult;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=tspathsTransform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+BAmHaA;;;WAAAA;;;;;kEAnHS;+BACU;uBACb;oEACK;sEACF;mEACH;qEACgB;sBACN;AAU7B,SAASC,cACPC,UACA,EAAEC,UAAUC,SAASC,MAAK,GAAmB;AAE7C,MAAI,CAACC,OAAEC,gBAAgBL,WAAW;AAChC;EACF;AAEA,QAAMM,aAAaN,SAASO,KAAKC;AACjC,QAAMC,cAAcR;AACpB,QAAMS,aAAYC,mCAChBT,SACAC,OACA;IAAC;GAAQ;AAEX,QAAMS,SAASF,UACbJ,YACAO;AACE,QAAI,CAACC,UAAGC,WAAWF,kBAAkB;AACnC,aAAOG;IACT;AACA,WAAOF,UAAGG,aAAaJ;EACzB,GACAK,cAAYJ,UAAGC,WAAWG,WAC1BC,kBAAY;AAEd,MAAIP,QAAQ;AACV,UAAMQ,eAAeC,MAAKC,SACxBD,MAAKE,QAAQd,cACbY,MAAKE,QAAQX;AAEf,UAAMY,WAAWH,MAAKI,SAASb;AAE/B,UAAMM,WAAWG,MAAKK,UACpB,GAAGN,aAAaO,WAAW,IAAI,MAAMP,gBAAgBI,UAAU;AAEjE,UAAMI,gBAAgBV,SAASW,WAAW,OAAOX,WAAW,KAAKA;AACjElB,aAAS8B,YAAY1B,OAAE2B,cAAcH;EACvC;AACF;AAgBA,MAAMI,kBACJ,CAACC,WAA4B,CAACjC;AAC5BD,gBAAcC,SAASkC,IAAI,WAAWD;AACxC;AAEF,MAAME,kBACJ,CAACF,WAA4B,CAACjC;AAC5BD,gBAAcC,SAASkC,IAAI,WAAwCD;AACrE;AAEF,MAAMG,2BAA2B,CAAC,EAChCnC,UACAC,SACAC,MAAK,MACW;AAChB,QAAMkC,aAAavB,UAAGwB,aAAarC,UAAU;AAC7C,QAAMsC,MAAMC,QAAOC,MAAMJ,YAAY;IACnCK,YAAY;IACZC,eAAe;IACfC,SAAS;MAAC;;EACZ;AACAC,yBAASN,KAAK;;;IAGZO,mBAAmBd,gBAAgB;MACjC/B;MACAC;MACAC;IACF;IACA4C,mBAAmBZ,gBAAgB;MACjClC;MACAC;MACAC;IACF;EACF;AACA,UAAO6C,uBAAUT,KAAKU;AACxB;AAOO,MAAMnD,oBAAoB,CAACmC;AAChC,QAAM,EAAEiB,YAAY,IAAIhD,SAASC,MAAK,IAAK8B;AAC3C,QAAMkB,kBAAuD;AAC7D,aAAWlD,YAAYiD,WAAW;AAChCC,oBAAgBC,KAAK;MACnB/B,MAAMpB;MACNoD,SAASjB,yBAAyB;QAAEnC;QAAUC;QAASC;MAAM;IAC/D;EACF;AACA,SAAOgD;AACT;","names":["transformDtsAlias","mapPathString","nodePath","filename","baseUrl","paths","t","isStringLiteral","sourcePath","node","value","currentFile","matchPath","createMatchPath","result","packageJsonPath","fs","existsSync","undefined","readJSONSync","filePath","dtsAliasExts","relativePath","path","relative","dirname","fileName","basename","normalize","length","replaceString","startsWith","replaceWith","stringLiteral","transformImport","option","get","transformExport","transformSingleFileAlias","sourceCode","readFileSync","ast","parser","parse","sourceType","errorRecovery","plugins","traverse","ImportDeclaration","ExportDeclaration","generator","code","filenames","transformResult","push","content"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/tspathsTransform.ts"],"sourcesContent":["import * as path from 'path';\nimport { createMatchPath } from '@modern-js/utils/tsconfig-paths';\nimport { fs } from '@modern-js/utils';\nimport * as parser from '@babel/parser';\nimport generator from '@babel/generator';\nimport * as t from '@babel/types';\nimport traverse, { NodePath } from '@babel/traverse';\nimport { dtsAliasExts } from '../constants/file';\n// import { defaultTransformedFunctions } from '../constants/dts';\n// import { matchesPattern, isImportCall } from './dts';\n\nexport interface TransformOption {\n filename: string;\n baseUrl: string;\n paths: Record<string, string[] | string>;\n}\n\nfunction mapPathString(\n nodePath: NodePath<any>,\n { filename, baseUrl, paths }: TransformOption,\n) {\n if (!t.isStringLiteral(nodePath)) {\n return;\n }\n\n const sourcePath = nodePath.node.value;\n const currentFile = filename;\n const matchPath = createMatchPath(\n baseUrl,\n paths as { [key: string]: Array<string> },\n ['index'],\n );\n const result = matchPath(\n sourcePath,\n packageJsonPath => {\n if (!fs.existsSync(packageJsonPath)) {\n return undefined;\n }\n return fs.readJSONSync(packageJsonPath);\n },\n filePath => fs.existsSync(filePath),\n dtsAliasExts,\n );\n if (result) {\n const relativePath = path.relative(\n path.dirname(currentFile),\n path.dirname(result),\n );\n const fileName = path.basename(result);\n // 如果是同级文件,则返回的是 ''\n const filePath = path.normalize(\n `${relativePath.length === 0 ? '.' : relativePath}/${fileName}`,\n );\n const replaceString = filePath.startsWith('.') ? filePath : `./${filePath}`;\n nodePath.replaceWith(t.stringLiteral(replaceString));\n }\n}\n\n// const transformCall =\n// (option: TransformOption) => (nodePath: NodePath<t.CallExpression>) => {\n// const calleePath = nodePath.get('callee') as NodePath;\n// const isNormalCall = defaultTransformedFunctions.some(pattern =>\n// matchesPattern(calleePath, pattern),\n// );\n// if (isNormalCall || isImportCall(nodePath)) {\n// mapPathString(\n// nodePath.get('arguments.0') as NodePath<t.StringLiteral>,\n// option,\n// );\n// }\n// };\n\nconst transformImport =\n (option: TransformOption) => (nodePath: NodePath<t.ImportDeclaration>) => {\n mapPathString(nodePath.get('source'), option);\n };\n\nconst transformExport =\n (option: TransformOption) => (nodePath: NodePath<t.ExportDeclaration>) => {\n mapPathString(nodePath.get('source') as NodePath<t.StringLiteral>, option);\n };\n\nconst transformSingleFileAlias = ({\n filename,\n baseUrl,\n paths,\n}: TransformOption) => {\n const sourceCode = fs.readFileSync(filename, 'utf-8');\n const ast = parser.parse(sourceCode, {\n sourceType: 'module',\n errorRecovery: true, // 防止typescript不支持的语法出现而报错\n plugins: ['typescript'],\n });\n traverse(ast, {\n // d.ts file content not have callExpression which can be parsed;\n // CallExpression: transformCall({ filename, baseUrl, paths }) as any,\n ImportDeclaration: transformImport({\n filename,\n baseUrl,\n paths,\n }) as any,\n ExportDeclaration: transformExport({\n filename,\n baseUrl,\n paths,\n }) as any,\n });\n return generator(ast).code;\n};\n\ninterface TransformDtsAliasOption {\n filenames?: string[];\n baseUrl: string;\n paths: Record<string, string[] | string>;\n}\nexport const transformDtsAlias = (option: TransformDtsAliasOption) => {\n const { filenames = [], baseUrl, paths } = option;\n const transformResult: { path: string; content: string }[] = [];\n for (const filename of filenames) {\n transformResult.push({\n path: filename,\n content: transformSingleFileAlias({ filename, baseUrl, paths }),\n });\n }\n return transformResult;\n};\n"]}
|
|
File without changes
|