@modern-js/module-tools 2.34.0 → 2.35.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/README.md +2 -2
- package/bin/modern.js +1 -1
- package/dist/builder/build.js +1 -1
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/dts/tsc.d.ts +1 -2
- package/dist/builder/dts/tsc.js +5 -21
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/types/dts.d.ts +3 -0
- package/dist/utils/dts.d.ts +7 -3
- package/dist/utils/dts.js +37 -12
- package/dist/utils/dts.js.map +1 -1
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<h1 align="center">Modern.js Module
|
|
5
|
+
<h1 align="center">Modern.js Module</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
Simple, powerful, high-performance modern npm package development solution.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
## Getting Started
|
|
12
12
|
|
|
13
|
-
Please follow [Quick Start](https://modernjs.dev/module-tools/en/guide/intro/getting-started.html) to get started with Modern.js Module
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/module-tools/en/guide/intro/getting-started.html) to get started with Modern.js Module.
|
|
14
14
|
|
|
15
15
|
## Documentation
|
|
16
16
|
|
package/bin/modern.js
CHANGED
package/dist/builder/build.js
CHANGED
|
@@ -121,7 +121,7 @@ const buildLib = async (config, api, options) => {
|
|
|
121
121
|
const { less, sass, postcss, inject, modules, autoModules } = style;
|
|
122
122
|
const { umdPlugin, swcTransformPlugin, transformPlugin: legacyTransformPlugin, es5Plugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/libuild-plugin-swc")));
|
|
123
123
|
const { checkSwcHelpers, matchEs5PluginCondition, matchSwcTransformCondition } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/builder")));
|
|
124
|
-
const { getProjectTsconfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("
|
|
124
|
+
const { getProjectTsconfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/dts")));
|
|
125
125
|
const tsconfigPath = dts ? dts.tsconfigPath : (0, _path.resolve)(appDirectory, "tsconfig.json");
|
|
126
126
|
const userTsconfig = await getProjectTsconfig(tsconfigPath);
|
|
127
127
|
const plugins = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAeaA,cAAY;WAAZA;;EAoBAC,kBAAgB;WAAhBA;;EAwBAC,kBAAgB;WAAhBA;;EAmBAC,cAAY;WAAZA;;EAqCAC,UAAQ;WAARA;;;;;sBAnHW;uBAEM;iEAUb;sBACQ;AAElB,MAAMJ,eAAe,OAC1BK,SAKAC;AAEA,QAAM,EAAEC,aAAaC,SAASC,gBAAe,IAAKJ;AAClD,QAAM,EAAEK,cAAcC,YAAW,IAAKH;AAEtC,SAAMI,mBAASL,aAAa;IAAEG;IAAcG,OAAOJ,gBAAgBI;EAAM;AAEzE,MAAIF,aAAa;AACf,UAAMV,iBAAiBI,SAASC;EAClC,OAAO;AACL,UAAMJ,iBAAiBG,SAASC;EAClC;AACF;AAEO,MAAML,mBAAmB,OAC9BI,SAKAC;AAEA,QAAM,EAAEC,aAAaE,gBAAe,IAAKJ;AACzC,QAAMS,MAAML,gBAAgBK,MAAMP,YAAYO,MAAM;AACpD,QAAMC,eAAeR,YAAYO,MAAMP,YAAYO,IAAIE,OAAO;MAChDP;AAAd,QAAMI,SAAQJ,yCAAgBI,WAAK,QAArBJ,6DAAyB;AAEvC,MAAIK,QAAQ,OAAO;AAE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C,UAAMC,sBAAsB,MAAMF,OAAOG,cAAcrG,aAAa;MAClEsG,QAAQC,OAAKA;IACf;AAEA,UAAMC,UAAU,MAAMR,UAAUS,OAAOL;AACvC,UAAMI,QAAQE,MAAK;AACnBT,mBAAeO,QAAQG,aAAaxD,MAAMnC,cAAc;AAExD,QAAIV,OAAO;AACT,YAAM,EAAEsG,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,YAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,YAAMC,YAAY,IAChB9F,cAAc,WAAW,WAAW,iBACjCc,UAAUF;AAEfmF,oBAAOC,KACL,MAAMJ,kBAAkBE,WAAWD,mBAAmBI,OAAO;IAEjE;EACF,SAASC,GAAP;AACA,UAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,UAAM,IAAIA,mBAAmBD,GAAG;MAC9BtF;MACAE;MACAd;IACF;EACF;AACF;","names":["runBuildTask","buildInTsProject","buildInJsProject","generatorDts","buildLib","options","api","buildConfig","context","buildCmdOptions","appDirectory","isTsProject","copyTask","watch","dts","skipBuildLib","only","tasks","pMap","task","config","runRollup","runTsc","buildType","input","sourceDir","alias","externals","useAppContext","tsconfigPath","distPath","abortOnError","respectExternal","distDir","distAbsPath","target","sourceMap","format","outDir","asset","jsx","platform","splitting","minify","umdGlobals","umdModuleName","define","style","autoExternal","metafile","sideEffects","redirect","esbuildOptions","externalHelpers","transformImport","transformLodash","sourceType","disableSwcTransform","root","slash","outdir","assetOutDir","path","less","sass","postcss","inject","modules","autoModules","umdPlugin","swcTransformPlugin","transformPlugin","legacyTransformPlugin","es5Plugin","checkSwcHelpers","matchEs5PluginCondition","matchSwcTransformCondition","getProjectTsconfig","resolve","userTsconfig","plugins","tsTargetAtOrAboveES2022","tsUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsTarget","toLowerCase","undefined","push","pluginImport","Boolean","emitDecoratorMetadata","jsc","transform","legacyDecorator","decoratorMetadata","svgr","svgrPlugin","watchPlugin","globals","external","bundle","outbase","Libuilder","addOutputChunk","runner","useHookRunners","modifiedBuildConfig","modifyLibuild","onLast","c","builder","create","build","outputChunk","watchSectionTitle","SectionTitleStatus","titleText","logger","info","Success","e","InternalBuildError"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/build.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type { CLIConfig } from '@modern-js/libuild';\nimport { slash, logger } from '@modern-js/utils';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n PluginAPI,\n DTSOptions,\n ModuleContext,\n TsTarget,\n} from '../types';\nimport pMap from '../../compiled/p-map';\nimport { copyTask } from './copy';\n\nexport const runBuildTask = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, context, buildCmdOptions } = options;\n const { appDirectory, isTsProject } = context;\n\n await copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });\n\n if (isTsProject) {\n await buildInTsProject(options, api);\n } else {\n await buildInJsProject(options, api);\n }\n};\n\nexport const buildInTsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts === false) {\n // --no-dts and buildConfig is `{ dts: { only: true } }`, then skip.\n !skipBuildLib && (await buildLib(buildConfig, api, { watch }));\n } else {\n const tasks = dts.only ? [generatorDts] : [buildLib, generatorDts];\n await pMap(tasks, async task => {\n await task(buildConfig, api as any, { watch, dts });\n });\n }\n};\n\nexport const buildInJsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts !== false && dts.only) {\n return;\n }\n\n await buildLib(buildConfig, api, { watch });\n};\n\nexport const generatorDts = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n dts: DTSOptions;\n },\n) => {\n const { runRollup, runTsc } = await import('./dts');\n const { watch, dts } = options;\n const { buildType, input, sourceDir, alias, externals } = config;\n const { appDirectory } = api.useAppContext();\n const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;\n if (buildType === 'bundle') {\n await runRollup(api, {\n distDir: distPath,\n watch,\n externals,\n input,\n tsconfigPath,\n abortOnError,\n respectExternal,\n appDirectory,\n });\n } else {\n await runTsc(api, {\n appDirectory,\n alias,\n distAbsPath: distPath,\n watch,\n tsconfigPath,\n sourceDir,\n abortOnError,\n });\n }\n};\n\nexport const buildLib = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n },\n) => {\n const { watch } = options;\n const {\n target,\n buildType,\n sourceMap,\n format,\n outDir: distPath,\n asset,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n umdGlobals,\n umdModuleName,\n define,\n alias,\n style,\n externals,\n autoExternal,\n dts,\n metafile,\n sideEffects,\n redirect,\n esbuildOptions,\n externalHelpers,\n transformImport,\n transformLodash,\n sourceType,\n disableSwcTransform,\n } = config;\n const { appDirectory } = api.useAppContext();\n const root = slash(appDirectory);\n const outdir = slash(distPath);\n const assetOutDir = asset.path ? slash(asset.path) : asset.path;\n const { less, sass, postcss, inject, modules, autoModules } = style;\n\n // support swc-transform, umd and emitDecoratorMetadata by swc\n const {\n umdPlugin,\n swcTransformPlugin,\n transformPlugin: legacyTransformPlugin,\n es5Plugin,\n } = await import('@modern-js/libuild-plugin-swc');\n const {\n checkSwcHelpers,\n matchEs5PluginCondition,\n matchSwcTransformCondition,\n } = await import('../utils/builder');\n\n const { getProjectTsconfig } = await import('./dts/tsc');\n const tsconfigPath = dts\n ? dts.tsconfigPath\n : resolve(appDirectory, 'tsconfig.json');\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n\n const plugins = [];\n\n if (\n matchSwcTransformCondition({\n sourceType,\n buildType,\n format,\n disableSwcTransform,\n })\n ) {\n // TODO: refactor config plugins logic\n\n const { tsTargetAtOrAboveES2022 } = await import('../utils/dts');\n const tsUseDefineForClassFields =\n userTsconfig?.compilerOptions?.useDefineForClassFields;\n let tsTarget = userTsconfig?.compilerOptions?.target;\n tsTarget = tsTarget ? (tsTarget.toLowerCase() as TsTarget) : undefined;\n let useDefineForClassFields: boolean;\n if (tsUseDefineForClassFields !== undefined) {\n useDefineForClassFields = tsUseDefineForClassFields;\n } else if (tsTarget !== undefined) {\n useDefineForClassFields = tsTargetAtOrAboveES2022(tsTarget);\n } else {\n useDefineForClassFields = true;\n }\n\n plugins.push(\n swcTransformPlugin({\n pluginImport: transformImport,\n transformLodash,\n externalHelpers: Boolean(externalHelpers),\n emitDecoratorMetadata:\n userTsconfig?.compilerOptions?.emitDecoratorMetadata,\n useDefineForClassFields,\n }),\n );\n } else {\n if (\n matchEs5PluginCondition({\n sourceType,\n buildType,\n format,\n target,\n disableSwcTransform,\n })\n ) {\n plugins.push(es5Plugin());\n }\n\n if (userTsconfig?.compilerOptions?.emitDecoratorMetadata) {\n plugins.push(\n legacyTransformPlugin({\n jsc: {\n transform: {\n legacyDecorator: true,\n decoratorMetadata: true,\n },\n },\n }),\n );\n }\n }\n\n if (format === 'umd') {\n plugins.push(umdPlugin(umdModuleName));\n }\n\n await checkSwcHelpers({ appDirectory, externalHelpers });\n\n // support svgr\n if (asset.svgr) {\n const { svgrPlugin } = await import('@modern-js/libuild-plugin-svgr');\n const options = typeof asset.svgr === 'boolean' ? {} : asset.svgr;\n plugins.push(svgrPlugin(options));\n }\n\n // adapt module tools\n const { watchPlugin } = await import('../utils/libuild-plugin');\n plugins.push(watchPlugin(api, config));\n\n const buildConfig: CLIConfig = {\n root,\n watch,\n target,\n sourceMap,\n format,\n outdir,\n define,\n style: {\n less,\n sass,\n postcss,\n inject,\n modules,\n autoModules,\n },\n resolve: {\n alias,\n },\n asset: {\n ...asset,\n outdir: assetOutDir,\n },\n plugins,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n metafile: metafile && buildType === 'bundle',\n globals: umdGlobals,\n external: externals,\n autoExternal,\n redirect,\n bundle: buildType === 'bundle',\n sideEffects,\n // outbase for [dir]/[name]\n outbase: sourceDir,\n esbuildOptions,\n };\n\n try {\n const { Libuilder } = await import('@modern-js/libuild');\n const { addOutputChunk } = await import('../utils/print');\n const runner = api.useHookRunners();\n const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {\n onLast: c => c,\n });\n\n const builder = await Libuilder.create(modifiedBuildConfig);\n await builder.build();\n addOutputChunk(builder.outputChunk, root, buildType === 'bundle');\n\n if (watch) {\n const { watchSectionTitle } = await import('../utils/log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }: ${format}_${target}]`;\n\n logger.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Success),\n );\n }\n } catch (e: any) {\n const { InternalBuildError } = await import('../error');\n throw new InternalBuildError(e, {\n target,\n format,\n buildType,\n });\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAeaA,cAAY;WAAZA;;EAoBAC,kBAAgB;WAAhBA;;EAwBAC,kBAAgB;WAAhBA;;EAmBAC,cAAY;WAAZA;;EAqCAC,UAAQ;WAARA;;;;;sBAnHW;uBAEM;iEAUb;sBACQ;AAElB,MAAMJ,eAAe,OAC1BK,SAKAC;AAEA,QAAM,EAAEC,aAAaC,SAASC,gBAAe,IAAKJ;AAClD,QAAM,EAAEK,cAAcC,YAAW,IAAKH;AAE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OAAO;MACLgB;MACAC;MACAC;MACAC;MACAC;MACAC;IACF;IACAU,SAAS;MACPpD;IACF;IACAa,OAAO;MACL,GAAGA;MACHqB,QAAQC;IACV;IACAmB;IACAxC;IACAhB;IACAiB;IACAC;IACAC;IACAlB;IACAwB,UAAUA,YAAY1B,cAAc;IACpC4E,SAASvD;IACTwD,UAAUzE;IACVqB;IACAG;IACAkD,QAAQ9E,cAAc;IACtB2B;;IAEAoD,SAAS7E;IACT2B;EACF;AAEA,MAAI;AACF,UAAM,EAAEmD,UAAS,IAAK,MAAM,iFAAO;AACnC,UAAM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,UAAMC,SAASnG,IAAIoG,eAAc;AACjC,UAAMC,sBAAsB,MAAMF,OAAOG,cAAcrG,aAAa;MAClEsG,QAAQC,OAAKA;IACf;AAEA,UAAMC,UAAU,MAAMR,UAAUS,OAAOL;AACvC,UAAMI,QAAQE,MAAK;AACnBT,mBAAeO,QAAQG,aAAaxD,MAAMnC,cAAc;AAExD,QAAIV,OAAO;AACT,YAAM,EAAEsG,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,YAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,YAAMC,YAAY,IAChB9F,cAAc,WAAW,WAAW,iBACjCc,UAAUF;AAEfmF,oBAAOC,KACL,MAAMJ,kBAAkBE,WAAWD,mBAAmBI,OAAO;IAEjE;EACF,SAASC,GAAP;AACA,UAAM,EAAEC,mBAAkB,IAAK,MAAM,iFAAO;AAC5C,UAAM,IAAIA,mBAAmBD,GAAG;MAC9BtF;MACAE;MACAd;IACF;EACF;AACF;","names":["runBuildTask","buildInTsProject","buildInJsProject","generatorDts","buildLib","options","api","buildConfig","context","buildCmdOptions","appDirectory","isTsProject","copyTask","watch","dts","skipBuildLib","only","tasks","pMap","task","config","runRollup","runTsc","buildType","input","sourceDir","alias","externals","useAppContext","tsconfigPath","distPath","abortOnError","respectExternal","distDir","distAbsPath","target","sourceMap","format","outDir","asset","jsx","platform","splitting","minify","umdGlobals","umdModuleName","define","style","autoExternal","metafile","sideEffects","redirect","esbuildOptions","externalHelpers","transformImport","transformLodash","sourceType","disableSwcTransform","root","slash","outdir","assetOutDir","path","less","sass","postcss","inject","modules","autoModules","umdPlugin","swcTransformPlugin","transformPlugin","legacyTransformPlugin","es5Plugin","checkSwcHelpers","matchEs5PluginCondition","matchSwcTransformCondition","getProjectTsconfig","resolve","userTsconfig","plugins","tsTargetAtOrAboveES2022","tsUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsTarget","toLowerCase","undefined","push","pluginImport","Boolean","emitDecoratorMetadata","jsc","transform","legacyDecorator","decoratorMetadata","svgr","svgrPlugin","watchPlugin","globals","external","bundle","outbase","Libuilder","addOutputChunk","runner","useHookRunners","modifiedBuildConfig","modifyLibuild","onLast","c","builder","create","build","outputChunk","watchSectionTitle","SectionTitleStatus","titleText","logger","info","Success","e","InternalBuildError"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/build.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type { CLIConfig } from '@modern-js/libuild';\nimport { slash, logger } from '@modern-js/utils';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n PluginAPI,\n DTSOptions,\n ModuleContext,\n TsTarget,\n} from '../types';\nimport pMap from '../../compiled/p-map';\nimport { copyTask } from './copy';\n\nexport const runBuildTask = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, context, buildCmdOptions } = options;\n const { appDirectory, isTsProject } = context;\n\n await copyTask(buildConfig, { appDirectory, watch: buildCmdOptions.watch });\n\n if (isTsProject) {\n await buildInTsProject(options, api);\n } else {\n await buildInJsProject(options, api);\n }\n};\n\nexport const buildInTsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts === false) {\n // --no-dts and buildConfig is `{ dts: { only: true } }`, then skip.\n !skipBuildLib && (await buildLib(buildConfig, api, { watch }));\n } else {\n const tasks = dts.only ? [generatorDts] : [buildLib, generatorDts];\n await pMap(tasks, async task => {\n await task(buildConfig, api as any, { watch, dts });\n });\n }\n};\n\nexport const buildInJsProject = async (\n options: {\n buildConfig: BaseBuildConfig;\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { buildConfig, buildCmdOptions } = options;\n const dts = buildCmdOptions.dts ? buildConfig.dts : false;\n const watch = buildCmdOptions.watch ?? false;\n\n if (dts !== false && dts.only) {\n return;\n }\n\n await buildLib(buildConfig, api, { watch });\n};\n\nexport const generatorDts = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n dts: DTSOptions;\n },\n) => {\n const { runRollup, runTsc } = await import('./dts');\n const { watch, dts } = options;\n const { buildType, input, sourceDir, alias, externals } = config;\n const { appDirectory } = api.useAppContext();\n const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;\n if (buildType === 'bundle') {\n await runRollup(api, {\n distDir: distPath,\n watch,\n externals,\n input,\n tsconfigPath,\n abortOnError,\n respectExternal,\n appDirectory,\n });\n } else {\n await runTsc(api, {\n appDirectory,\n alias,\n distAbsPath: distPath,\n watch,\n tsconfigPath,\n sourceDir,\n abortOnError,\n });\n }\n};\n\nexport const buildLib = async (\n config: BaseBuildConfig,\n api: PluginAPI<ModuleTools>,\n options: {\n watch: boolean;\n },\n) => {\n const { watch } = options;\n const {\n target,\n buildType,\n sourceMap,\n format,\n outDir: distPath,\n asset,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n umdGlobals,\n umdModuleName,\n define,\n alias,\n style,\n externals,\n autoExternal,\n dts,\n metafile,\n sideEffects,\n redirect,\n esbuildOptions,\n externalHelpers,\n transformImport,\n transformLodash,\n sourceType,\n disableSwcTransform,\n } = config;\n const { appDirectory } = api.useAppContext();\n const root = slash(appDirectory);\n const outdir = slash(distPath);\n const assetOutDir = asset.path ? slash(asset.path) : asset.path;\n const { less, sass, postcss, inject, modules, autoModules } = style;\n\n // support swc-transform, umd and emitDecoratorMetadata by swc\n const {\n umdPlugin,\n swcTransformPlugin,\n transformPlugin: legacyTransformPlugin,\n es5Plugin,\n } = await import('@modern-js/libuild-plugin-swc');\n const {\n checkSwcHelpers,\n matchEs5PluginCondition,\n matchSwcTransformCondition,\n } = await import('../utils/builder');\n\n const { getProjectTsconfig } = await import('../utils/dts');\n const tsconfigPath = dts\n ? dts.tsconfigPath\n : resolve(appDirectory, 'tsconfig.json');\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n\n const plugins = [];\n\n if (\n matchSwcTransformCondition({\n sourceType,\n buildType,\n format,\n disableSwcTransform,\n })\n ) {\n // TODO: refactor config plugins logic\n\n const { tsTargetAtOrAboveES2022 } = await import('../utils/dts');\n const tsUseDefineForClassFields =\n userTsconfig?.compilerOptions?.useDefineForClassFields;\n let tsTarget = userTsconfig?.compilerOptions?.target;\n tsTarget = tsTarget ? (tsTarget.toLowerCase() as TsTarget) : undefined;\n let useDefineForClassFields: boolean;\n if (tsUseDefineForClassFields !== undefined) {\n useDefineForClassFields = tsUseDefineForClassFields;\n } else if (tsTarget !== undefined) {\n useDefineForClassFields = tsTargetAtOrAboveES2022(tsTarget);\n } else {\n useDefineForClassFields = true;\n }\n\n plugins.push(\n swcTransformPlugin({\n pluginImport: transformImport,\n transformLodash,\n externalHelpers: Boolean(externalHelpers),\n emitDecoratorMetadata:\n userTsconfig?.compilerOptions?.emitDecoratorMetadata,\n useDefineForClassFields,\n }),\n );\n } else {\n if (\n matchEs5PluginCondition({\n sourceType,\n buildType,\n format,\n target,\n disableSwcTransform,\n })\n ) {\n plugins.push(es5Plugin());\n }\n\n if (userTsconfig?.compilerOptions?.emitDecoratorMetadata) {\n plugins.push(\n legacyTransformPlugin({\n jsc: {\n transform: {\n legacyDecorator: true,\n decoratorMetadata: true,\n },\n },\n }),\n );\n }\n }\n\n if (format === 'umd') {\n plugins.push(umdPlugin(umdModuleName));\n }\n\n await checkSwcHelpers({ appDirectory, externalHelpers });\n\n // support svgr\n if (asset.svgr) {\n const { svgrPlugin } = await import('@modern-js/libuild-plugin-svgr');\n const options = typeof asset.svgr === 'boolean' ? {} : asset.svgr;\n plugins.push(svgrPlugin(options));\n }\n\n // adapt module tools\n const { watchPlugin } = await import('../utils/libuild-plugin');\n plugins.push(watchPlugin(api, config));\n\n const buildConfig: CLIConfig = {\n root,\n watch,\n target,\n sourceMap,\n format,\n outdir,\n define,\n style: {\n less,\n sass,\n postcss,\n inject,\n modules,\n autoModules,\n },\n resolve: {\n alias,\n },\n asset: {\n ...asset,\n outdir: assetOutDir,\n },\n plugins,\n jsx,\n input,\n platform,\n splitting,\n minify,\n sourceDir,\n metafile: metafile && buildType === 'bundle',\n globals: umdGlobals,\n external: externals,\n autoExternal,\n redirect,\n bundle: buildType === 'bundle',\n sideEffects,\n // outbase for [dir]/[name]\n outbase: sourceDir,\n esbuildOptions,\n };\n\n try {\n const { Libuilder } = await import('@modern-js/libuild');\n const { addOutputChunk } = await import('../utils/print');\n const runner = api.useHookRunners();\n const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {\n onLast: c => c,\n });\n\n const builder = await Libuilder.create(modifiedBuildConfig);\n await builder.build();\n addOutputChunk(builder.outputChunk, root, buildType === 'bundle');\n\n if (watch) {\n const { watchSectionTitle } = await import('../utils/log');\n const { SectionTitleStatus } = await import('../constants/log');\n const titleText = `[${\n buildType === 'bundle' ? 'Bundle' : 'Bundleless'\n }: ${format}_${target}]`;\n\n logger.info(\n await watchSectionTitle(titleText, SectionTitleStatus.Success),\n );\n }\n } catch (e: any) {\n const { InternalBuildError } = await import('../error');\n throw new InternalBuildError(e, {\n target,\n format,\n buildType,\n });\n }\n};\n"]}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { BundlelessGeneratorDtsConfig,
|
|
2
|
-
export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
|
|
1
|
+
import type { BundlelessGeneratorDtsConfig, PluginAPI, ModuleTools } from '../../types';
|
|
3
2
|
export declare const runTsc: (api: PluginAPI<ModuleTools>, config: BundlelessGeneratorDtsConfig) => Promise<void>;
|
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -2,18 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: all[name]
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
_export(exports, {
|
|
13
|
-
getProjectTsconfig: function() {
|
|
14
|
-
return getProjectTsconfig;
|
|
15
|
-
},
|
|
16
|
-
runTsc: function() {
|
|
5
|
+
Object.defineProperty(exports, "runTsc", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
17
8
|
return runTsc;
|
|
18
9
|
}
|
|
19
10
|
});
|
|
@@ -23,12 +14,6 @@ const _dts = require("../../utils/dts");
|
|
|
23
14
|
const _log = require("../../utils/log");
|
|
24
15
|
const _log1 = require("../../constants/log");
|
|
25
16
|
const _dts1 = require("../../constants/dts");
|
|
26
|
-
const getProjectTsconfig = async (tsconfigPath) => {
|
|
27
|
-
if (!_utils.fs.existsSync(tsconfigPath)) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, "utf-8"));
|
|
31
|
-
};
|
|
32
17
|
const resolveLog = async (childProgress, options) => {
|
|
33
18
|
var _childProgress_stdout, _childProgress_stdout1, _childProgress_stderr;
|
|
34
19
|
const { watch = false, watchFn = async () => void 0 } = options;
|
|
@@ -49,9 +34,8 @@ const resolveLog = async (childProgress, options) => {
|
|
|
49
34
|
});
|
|
50
35
|
};
|
|
51
36
|
const generatorDts = async (api, config) => {
|
|
52
|
-
const {
|
|
53
|
-
const userTsconfig = await
|
|
54
|
-
const result = await (0, _dts.generatorTsConfig)(config);
|
|
37
|
+
const { appDirectory, watch = false, abortOnError = true } = config;
|
|
38
|
+
const { userTsconfig, generatedTsconfig: result } = await (0, _dts.generatorTsConfig)(config);
|
|
55
39
|
const tscBinFile = await (0, _dts.getTscBinPath)(appDirectory);
|
|
56
40
|
const watchParams = watch ? [
|
|
57
41
|
"-w"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;+BAuGaA;;;WAAAA;;;uBAtGiB;uBACF;qBAWrB;qBAC2B;sBAI3B;sBACuB;AAE9B,MAAMC,aAAa,OACjBC,eACAC;MAYAD,uBAYAA,wBAGAA;AAtBA,QAAM,EAAEE,QAAQ,OAAOC,UAAU,YAAYC,OAAS,IAAKH;GAO3DD,sCAAcK,YAAM,QAApBL,kEAAsBM,GAAG,QAAQ,OAAMC;AACrC,QAAIL,OAAO;AACTM,oBAAOC,KACL,OAAMC,2BAAkBC,8BAAwBC,yBAAmBC,GAAG;AAExEL,oBAAOC,KAAKF,KAAKO,SAAQ;AACzB,UAAIP,KAAKO,SAAQ,EAAGC,SAASC,mBAAa,GAAG;AAC3C,cAAMb;MACR;IACF;EACF;GAEAH,uCAAcK,YAAM,QAApBL,oEAAsBM,GAAG,SAASW;AAChCT,kBAAOS,MAAMA,MAAMC,OAAO;EAC5B;GACAlB,sCAAcmB,YAAM,QAApBnB,kEAAsBM,GAAG,QAAQc;AAC/BZ,kBAAOS,MAAMG,MAAMN,SAAQ;EAC7B;AACF;AAEA,MAAMO,eAAe,OACnBC,KACAC;AAEA,QAAM,EAAEC,cAActB,QAAQ,OAAOuB,eAAe,KAAI,IAAKF;AAE7D,QAAM,EAAEG,cAAcC,mBAAmBC,OAAM,IAAK,OAAMC,2BACxDN;AAGF,QAAMO,aAAa,OAAMC,uBAAcP;AAEvC,QAAMQ,cAAc9B,QAAQ;IAAC;MAAQ;AACrC,QAAMF,iBAAgBiC,iBACpBH,YACA;IACE;IACAF,OAAOM;;IAEP;;IAEA;OACGF;KAEL;IACEG,OAAO;IACPC,KAAKZ;EACP;AAGF,QAAMa,SAASf,IAAIgB,eAAc;AACjCvC,aAAWC,eAAe;IACxBE;IACAC,SAAS;AACP,aAAMoC,sBAAahB,QAAQ;QAAE,GAAGK;QAAQF;MAAa;AACrDW,aAAOG,cAAc;QAAEC,WAAW;MAAa;IACjD;EACF;AAEA,MAAI;AACF,UAAMzC;EACR,SAAS0C,GAAP;AACA,WAAMC,+BAAsBD,GAAG;MAAEjB;MAAcgB,WAAW;IAAa;EACzE;AAEA,SAAO;IAAE,GAAGb;IAAQF;EAAa;AACnC;AAEO,MAAM5B,SAAS,OACpBwB,KACAC;AAEA,QAAMK,SAAS,MAAMP,aAAaC,KAAKC;AACvC,SAAMgB,sBAAahB,QAAQK;AAC3B,SAAMgB,uBAAYrB,OAAOsB,aAAatB,OAAOC,YAAY;AAC3D;","names":["runTsc","resolveLog","childProgress","options","watch","watchFn","undefined","stdout","on","data","logger","info","watchSectionTitle","BundlelessDtsLogPrefix","SectionTitleStatus","Log","toString","includes","watchDoneText","error","message","stderr","chunk","generatorDts","api","config","appDirectory","abortOnError","userTsconfig","generatedTsconfig","result","generatorTsConfig","tscBinFile","getTscBinPath","watchParams","execa","tempTsconfigPath","stdio","cwd","runner","useHookRunners","resolveAlias","buildWatchDts","buildType","e","printOrThrowDtsErrors","addDtsFiles","distAbsPath"],"sources":["../../../src/builder/dts/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/dts/tsc.ts"],"sourcesContent":["import type { ChildProcess } from 'child_process';\nimport { execa, logger } from '@modern-js/utils';\nimport { addDtsFiles } from '../../utils/print';\nimport type {\n BundlelessGeneratorDtsConfig,\n PluginAPI,\n ModuleTools,\n} from '../../types';\nimport {\n generatorTsConfig,\n getTscBinPath,\n printOrThrowDtsErrors,\n resolveAlias,\n} from '../../utils/dts';\nimport { watchSectionTitle } from '../../utils/log';\nimport {\n BundlelessDtsLogPrefix,\n SectionTitleStatus,\n} from '../../constants/log';\nimport { watchDoneText } from '../../constants/dts';\n\nconst resolveLog = async (\n childProgress: ChildProcess,\n options: {\n watch: boolean;\n watchFn: () => Promise<void>;\n },\n) => {\n const { watch = false, watchFn = async () => undefined } = options;\n\n /**\n * tsc 所有的log信息都是从stdout data 事件中获取\n * 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理\n * watch 模式下,则使用这里的信息\n */\n childProgress.stdout?.on('data', async data => {\n if (watch) {\n logger.info(\n await watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log),\n );\n logger.info(data.toString());\n if (data.toString().includes(watchDoneText)) {\n await watchFn();\n }\n }\n });\n // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况\n childProgress.stdout?.on('error', error => {\n logger.error(error.message);\n });\n childProgress.stderr?.on('data', chunk => {\n logger.error(chunk.toString());\n });\n};\n\nconst generatorDts = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { appDirectory, watch = false, abortOnError = true } = config;\n\n const { userTsconfig, generatedTsconfig: result } = await generatorTsConfig(\n config,\n );\n\n const tscBinFile = await getTscBinPath(appDirectory);\n\n const watchParams = watch ? ['-w'] : [];\n const childProgress = execa(\n tscBinFile,\n [\n '-p',\n result.tempTsconfigPath,\n /* Required parameter, use it stdout have color */\n '--pretty',\n // https://github.com/microsoft/TypeScript/issues/21824\n '--preserveWatchOutput',\n ...watchParams,\n ],\n {\n stdio: 'pipe',\n cwd: appDirectory,\n },\n );\n\n const runner = api.useHookRunners();\n resolveLog(childProgress, {\n watch,\n watchFn: async () => {\n await resolveAlias(config, { ...result, userTsconfig });\n runner.buildWatchDts({ buildType: 'bundleless' });\n },\n });\n\n try {\n await childProgress;\n } catch (e) {\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundleless' });\n }\n\n return { ...result, userTsconfig };\n};\n\nexport const runTsc = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const result = await generatorDts(api, config);\n await resolveAlias(config, result);\n await addDtsFiles(config.distAbsPath, config.appDirectory);\n};\n"]}
|
package/dist/types/dts.d.ts
CHANGED
package/dist/utils/dts.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ITsconfig, BundlelessGeneratorDtsConfig, BuildType, TsTarget } from '../types';
|
|
2
|
+
export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
|
|
2
3
|
export declare const generatorTsConfig: (config: BundlelessGeneratorDtsConfig) => Promise<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
userTsconfig: ITsconfig;
|
|
5
|
+
generatedTsconfig: {
|
|
6
|
+
tempTsconfigPath: string;
|
|
7
|
+
tempDistAbsRootPath: string;
|
|
8
|
+
tempDistAbsSrcPath: string;
|
|
9
|
+
};
|
|
6
10
|
}>;
|
|
7
11
|
export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
|
|
8
12
|
export declare const resolveAlias: (config: BundlelessGeneratorDtsConfig, options: {
|
package/dist/utils/dts.js
CHANGED
|
@@ -10,6 +10,9 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
+
getProjectTsconfig: function() {
|
|
14
|
+
return getProjectTsconfig;
|
|
15
|
+
},
|
|
13
16
|
generatorTsConfig: function() {
|
|
14
17
|
return generatorTsConfig;
|
|
15
18
|
},
|
|
@@ -26,18 +29,36 @@ _export(exports, {
|
|
|
26
29
|
return tsTargetAtOrAboveES2022;
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
30
32
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
31
|
-
const _path =
|
|
33
|
+
const _path = require("path");
|
|
32
34
|
const _utils = require("@modern-js/utils");
|
|
35
|
+
const getProjectTsconfig = async (tsconfigPath) => {
|
|
36
|
+
if (!_utils.fs.existsSync(tsconfigPath)) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, "utf-8"));
|
|
40
|
+
};
|
|
33
41
|
const generatorTsConfig = async (config) => {
|
|
34
|
-
|
|
42
|
+
var _userTsconfig_references, _userTsconfig;
|
|
35
43
|
const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
44
|
+
const userTsconfig = await getProjectTsconfig(tsconfigPath);
|
|
45
|
+
const { dtsTempDirectory } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/dts")));
|
|
46
|
+
const tempDistAbsRootPath = (0, _path.join)(appDirectory, `${dtsTempDirectory}/${(0, _utils.nanoid)()}`);
|
|
47
|
+
const tempDistAbsOurDir = (0, _path.join)(tempDistAbsRootPath, (0, _path.relative)(appDirectory, absSourceDir));
|
|
48
|
+
const tempTsconfigPath = (0, _path.join)(tempDistAbsRootPath, (0, _path.basename)(tsconfigPath));
|
|
39
49
|
_utils.fs.ensureFileSync(tempTsconfigPath);
|
|
40
|
-
const extendsPath = _path.
|
|
50
|
+
const extendsPath = (0, _path.join)((0, _path.relative)((0, _path.dirname)(tempTsconfigPath), (0, _path.dirname)(tsconfigPath)), (0, _path.basename)(tempTsconfigPath));
|
|
51
|
+
const references = (_userTsconfig = userTsconfig) === null || _userTsconfig === void 0 ? void 0 : (_userTsconfig_references = _userTsconfig.references) === null || _userTsconfig_references === void 0 ? void 0 : _userTsconfig_references.map((reference) => {
|
|
52
|
+
const { path } = reference;
|
|
53
|
+
if (path) {
|
|
54
|
+
const userTsconfigDir = (0, _path.dirname)(tsconfigPath);
|
|
55
|
+
const generatedTsconfigDir = (0, _path.dirname)(tempTsconfigPath);
|
|
56
|
+
return {
|
|
57
|
+
path: (0, _path.isAbsolute)(path) ? path : (0, _path.relative)(generatedTsconfigDir, (0, _path.resolve)(userTsconfigDir, path))
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return reference;
|
|
61
|
+
});
|
|
41
62
|
const resetConfig = {
|
|
42
63
|
extends: extendsPath,
|
|
43
64
|
compilerOptions: {
|
|
@@ -50,19 +71,23 @@ const generatorTsConfig = async (config) => {
|
|
|
50
71
|
// - ./types/index.d.ts
|
|
51
72
|
// we only want to emit declarations
|
|
52
73
|
declarationDir: tempDistAbsOurDir
|
|
53
|
-
}
|
|
74
|
+
},
|
|
75
|
+
references
|
|
54
76
|
};
|
|
55
77
|
_utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
|
|
56
78
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
userTsconfig,
|
|
80
|
+
generatedTsconfig: {
|
|
81
|
+
tempTsconfigPath,
|
|
82
|
+
tempDistAbsRootPath,
|
|
83
|
+
tempDistAbsSrcPath: tempDistAbsOurDir
|
|
84
|
+
}
|
|
60
85
|
};
|
|
61
86
|
};
|
|
62
87
|
const getTscBinPath = async (appDirectory) => {
|
|
63
88
|
const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/find-up")));
|
|
64
89
|
const tscBinFile = await findUp(async (directory) => {
|
|
65
|
-
const targetFilePath = _path.
|
|
90
|
+
const targetFilePath = (0, _path.join)(directory, "./node_modules/.bin/tsc");
|
|
66
91
|
const hasTscBinFile = await pathExists(targetFilePath);
|
|
67
92
|
if (hasTscBinFile) {
|
|
68
93
|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AAW;","names":["generatorTsConfig","getTscBinPath","resolveAlias","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","config","dtsTempDirectory","appDirectory","sourceDir","absSourceDir","tsconfigPath","tempDistAbsRootPath","path","join","nanoid","tempDistAbsOurDir","relative","tempTsconfigPath","basename","fs","ensureFileSync","extendsPath","dirname","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","existsSync","Error","options","watchFilenames","userTsconfig","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","globby","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","ensureDir","copy","error","InternalDTSError","local","abortOnError","buildType","logger","warn","chalk","bgYellowBright","i18n","t","localeKeys","warns","dts","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import path from 'path';\nimport { chalk, fs, globby, logger, nanoid } from '@modern-js/utils';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildType,\n TsTarget,\n} from '../types';\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n const tempDistAbsRootPath = path.join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = path.join(\n tempDistAbsRootPath,\n path.relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = path.join(\n tempDistAbsRootPath,\n path.basename(tsconfigPath),\n );\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = path.join(\n path.relative(path.dirname(tempTsconfigPath), path.dirname(tsconfigPath)),\n path.basename(tempTsconfigPath),\n );\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = path.join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n // why use `ensureDir` before copy? look this: https://github.com/jprichardson/node-fs-extra/issues/957\n await fs.ensureDir(distAbsPath);\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EASaA,oBAAkB;WAAlBA;;EAUAC,mBAAiB;WAAjBA;;EAkEAC,eAAa;WAAbA;;EAyBAC,c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1B,QAAIuB,cAAc;AAChB,YAAM,IAAIF,iBAAiBD,OAAO;QAChCI;MACF;IACF,OAAO;AACLC,oBAAOC,KACLC,aAAMC,eACJN,MAAMO,KAAKC,EAAER,MAAMS,WAAWC,MAAMC,IAAIV,YAAY;AAGxDE,oBAAOL,MACL,IAAIC,iBAAiBD,OAAO;QAC1BI;MACF;IAEJ;EACF;AACF;AAEO,MAAM1E,0BAA0B,CAACoF,WACtCA,WAAW,YAAYA,WAAW;","names":["getProjectTsconfig","generatorTsConfig","getTscBinPath","resolveAlias","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","tsconfigPath","fs","existsSync","json5","parse","readFileSync","config","userTsconfig","appDirectory","sourceDir","absSourceDir","dtsTempDirectory","tempDistAbsRootPath","join","nanoid","tempDistAbsOurDir","relative","tempTsconfigPath","basename","ensureFileSync","extendsPath","dirname","references","map","reference","path","userTsconfigDir","generatedTsconfigDir","isAbsolute","resolve","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","generatedTsconfig","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","Error","options","watchFilenames","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","globby","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","ensureDir","copy","error","InternalDTSError","local","abortOnError","buildType","logger","warn","chalk","bgYellowBright","i18n","t","localeKeys","warns","dts","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import { join, dirname, isAbsolute, relative, resolve, basename } from 'path';\nimport { chalk, fs, globby, json5, logger, nanoid } from '@modern-js/utils';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildType,\n TsTarget,\n} from '../types';\n\nexport const getProjectTsconfig = async (\n tsconfigPath: string,\n): Promise<ITsconfig> => {\n if (!fs.existsSync(tsconfigPath)) {\n return {};\n }\n\n return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));\n};\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const tempDistAbsRootPath = join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = join(\n tempDistAbsRootPath,\n relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = join(tempDistAbsRootPath, basename(tsconfigPath));\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = join(\n relative(dirname(tempTsconfigPath), dirname(tsconfigPath)),\n basename(tempTsconfigPath),\n );\n const references = userTsconfig?.references?.map(reference => {\n const { path } = reference;\n if (path) {\n const userTsconfigDir = dirname(tsconfigPath);\n const generatedTsconfigDir = dirname(tempTsconfigPath);\n return {\n path: isAbsolute(path)\n ? path\n : relative(generatedTsconfigDir, resolve(userTsconfigDir, path)),\n };\n }\n return reference;\n });\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n references,\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n userTsconfig,\n generatedTsconfig: {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n },\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n // why use `ensureDir` before copy? look this: https://github.com/jprichardson/node-fs-extra/issues/957\n await fs.ensureDir(distAbsPath);\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"module-tools",
|
|
16
16
|
"lib-tools"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.35.0",
|
|
19
19
|
"bin": {
|
|
20
20
|
"modern": "./bin/modern.js",
|
|
21
21
|
"modern-module": "./bin/modern.js"
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"@babel/traverse": "^7.22.15",
|
|
56
56
|
"postcss": "8.4.27",
|
|
57
57
|
"@swc/helpers": "0.5.1",
|
|
58
|
-
"@modern-js/core": "2.
|
|
59
|
-
"@modern-js/libuild": "2.
|
|
60
|
-
"@modern-js/libuild-plugin-svgr": "2.
|
|
61
|
-
"@modern-js/libuild-plugin-swc": "2.
|
|
62
|
-
"@modern-js/new-action": "2.
|
|
63
|
-
"@modern-js/plugin": "2.
|
|
64
|
-
"@modern-js/plugin-changeset": "2.
|
|
65
|
-
"@modern-js/plugin-i18n": "2.
|
|
66
|
-
"@modern-js/plugin-lint": "2.
|
|
67
|
-
"@modern-js/types": "2.
|
|
68
|
-
"@modern-js/upgrade": "2.
|
|
69
|
-
"@modern-js/utils": "2.
|
|
58
|
+
"@modern-js/core": "2.35.0",
|
|
59
|
+
"@modern-js/libuild": "2.35.0",
|
|
60
|
+
"@modern-js/libuild-plugin-svgr": "2.35.0",
|
|
61
|
+
"@modern-js/libuild-plugin-swc": "2.35.0",
|
|
62
|
+
"@modern-js/new-action": "2.35.0",
|
|
63
|
+
"@modern-js/plugin": "2.35.0",
|
|
64
|
+
"@modern-js/plugin-changeset": "2.35.0",
|
|
65
|
+
"@modern-js/plugin-i18n": "2.35.0",
|
|
66
|
+
"@modern-js/plugin-lint": "2.35.0",
|
|
67
|
+
"@modern-js/types": "2.35.0",
|
|
68
|
+
"@modern-js/upgrade": "2.35.0",
|
|
69
|
+
"@modern-js/utils": "2.35.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/babel__generator": "7.6.4",
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"jest": "^29",
|
|
80
80
|
"path-browserify": "1.0.1",
|
|
81
81
|
"postcss-alias": "2.0.0",
|
|
82
|
-
"react": "
|
|
82
|
+
"react": "^18",
|
|
83
83
|
"typescript": "^5",
|
|
84
|
-
"@modern-js/builder-webpack-provider": "2.
|
|
85
|
-
"@modern-js/self": "npm:@modern-js/module-tools@2.
|
|
86
|
-
"@scripts/build": "2.
|
|
87
|
-
"@scripts/jest-config": "2.
|
|
84
|
+
"@modern-js/builder-webpack-provider": "2.35.0",
|
|
85
|
+
"@modern-js/self": "npm:@modern-js/module-tools@2.35.0",
|
|
86
|
+
"@scripts/build": "2.35.0",
|
|
87
|
+
"@scripts/jest-config": "2.35.0"
|
|
88
88
|
},
|
|
89
89
|
"publishConfig": {
|
|
90
90
|
"registry": "https://registry.npmjs.org/",
|