@sanity/pkg-utils 10.9.2 → 11.0.1
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/dist/_chunks-es/buildAction.js.map +1 -1
- package/dist/_chunks-es/createApiExtractorConfig.js +0 -1
- package/dist/_chunks-es/createApiExtractorConfig.js.map +1 -1
- package/dist/_chunks-es/extractModuleBlocks.js +1 -1
- package/dist/_chunks-es/extractModuleBlocks.js.map +1 -1
- package/dist/_chunks-es/index.js +16 -12
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/initAction.js.map +1 -1
- package/dist/_chunks-es/resolveBuildContext.js +1 -1
- package/dist/_chunks-es/resolveBuildContext.js.map +1 -1
- package/dist/_chunks-es/resolveRolldownConfig.js +8 -2
- package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -1
- package/dist/_chunks-es/watchAction.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +21 -26
- package/dist/index.d.ts.map +1 -1
- package/package.json +10 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAction.js","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/build.ts","../../src/cli/buildAction.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types.ts'\nimport type {BuildContext} from './core/contexts/buildContext.ts'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths.ts'\nimport type {DtsTask} from './tasks/dts/types.ts'\nimport type {BuildTask, RolldownDtsTask, RollupTask, RollupTaskEntry} from './tasks/types.ts'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, pkg, target} = ctx\n\n const bundles = config?.bundles || []\n\n const tasks: BuildTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => Object.assign({}, exp, {_path}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsTask = {\n type: 'build:dts',\n entries: [],\n }\n\n const rolldownDtsTask: Record<string, RolldownDtsTask> = {}\n const rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (ctx.dts === 'rolldown') {\n if (rolldownDtsTask[buildId]) {\n rolldownDtsTask[buildId].entries.push(entry)\n } else {\n rolldownDtsTask[buildId] = {\n type: 'rolldown:dts',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n if (!ctx.emitDeclarationOnly) {\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n }\n\n if (ctx.dts === 'api-extractor') {\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Handle dts tasks for bundles\n for (const bundle of bundles) {\n if (bundle.source?.endsWith('.ts')) {\n // importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`\n // exportPath needs to be the path to the bundle, like `./dist/cli`\n // targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]\n const exportPath = (bundle.import || bundle.require)!.replace(/\\.[mc]?js$/, '')\n const importId = path.join(pkg.name, exportPath)\n\n dtsTask.entries.push({\n importId,\n exportPath,\n sourcePath: bundle.source,\n targetPaths: getTargetPaths(pkg.type, bundle),\n })\n }\n }\n\n // Add dts task\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:node tasks\n for (const exp of exports) {\n const output = exp.node?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'node', {\n path: exp._path,\n source: exp.node?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:node tasks\n for (const exp of exports) {\n const output = exp.node?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'node', {\n path: exp._path,\n source: exp.node?.source || exp.source,\n output,\n })\n }\n\n for (const bundle of bundles) {\n const idx = bundles.indexOf(bundle)\n\n if (bundle.require) {\n addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_cjs_${idx}$$__`,\n source: bundle.source,\n output: bundle.require,\n })\n }\n\n if (bundle.import) {\n addRollupTaskEntry('esm', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_esm_${idx}$$__`,\n source: bundle.source,\n output: bundle.import,\n })\n }\n }\n\n // Perform rolldown dts tasks first, as they have special logic for removing non .d.ts chunks\n tasks.push(...Object.values(rolldownDtsTask))\n // Then run api-extractor tsdoc release tag checking (if rolldown is used for dts bundling, otherwise api-extractor performs both in the build:dts task)\n // @TODO\n // Then run rollup tasks\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport {up as findPkgPath} from 'empathic/package'\nimport {rimraf} from 'rimraf'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {resolveVanillaExtract, resolveVanillaExtractCssName} from './core/config/vanillaExtract.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {writeBundleCssExports} from './core/pkg/writeBundleCssExports.ts'\nimport {createLogger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {resolveBuildTasks} from './resolveBuildTasks.ts'\nimport {createSpinner} from './spinner.ts'\nimport {buildTaskHandlers} from './tasks/index.ts'\nimport {type BuildTask, type TaskHandler} from './tasks/types.ts'\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n clean = false,\n quiet = false,\n } = options\n const logger = createLogger(quiet)\n\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('no package.json found', {cause: {cwd}})\n }\n const config = await loadConfig({cwd, pkgPath})\n\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n if (clean) {\n if (!quiet) {\n logger.log(\n `Deleting the \\`dist\\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,\n )\n }\n await rimraf(ctx.distPath)\n }\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- TypeScript can't infer the correct handler type from discriminated union\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName, quiet)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(cwd, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n\n // In vanilla-extract compat mode, make sure package.json declares the conditional `./<css>`\n // export that the injected `import \"<pkg>/<css>\"` resolves through.\n const vanillaExtract = resolveVanillaExtract(config)\n if (vanillaExtract.compatMode) {\n await writeBundleCssExports({\n cwd,\n distPath: ctx.distPath,\n cssName: resolveVanillaExtractCssName(vanillaExtract.options, {\n compatMode: true,\n runtime: '*',\n }),\n logger,\n })\n }\n}\n","import {build} from '../node/build.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function buildAction(options: {\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n try {\n await build({\n cwd: process.cwd(),\n emitDeclarationOnly: options.emitDeclarationOnly,\n strict: options.strict,\n tsconfig: options.tsconfig,\n clean: options.clean,\n quiet: options.quiet,\n })\n } catch (err)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AI,OAAO,KAAK,GAAG;AAElC,YAAI,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GACjD,IAAI,OAAO,IAAA;AAAA,MACb;AAEA,cAAQ,MAAM,KAAK,MAAM,GAAG,GAE5B,QAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAIA,QAAM,iBAAiB,sBAAsB,MAAM;AAC/C,iBAAe,cACjB,MAAM,sBAAsB;AAAA,IAC1B;AAAA,IACA,UAAU,IAAI;AAAA,IACd,SAAS,6BAA6B,eAAe,SAAS;AAAA,MAC5D,YAAY;AAAA,MACZ,SAAS;AAAA,IAAA,CACV;AAAA,IACD;AAAA,EAAA,CACD;AAEL;AC7HA,eAAsB,YAAY,SAMhB;AAChB,MAAI;AACF,UAAM,MAAM;AAAA,MACV,KAAK,QAAQ,IAAA;AAAA,MACb,qBAAqB,QAAQ;AAAA,MAC7B,QAAQ,QAAQ;AAAA,MAChB,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,MACf,OAAO,QAAQ;AAAA,IAAA,CAChB;AAAA,EACH,SAAS,KAAK;AACZ,gBAAY,GAAG;AAAA,EACjB;AACF;"}
|
|
1
|
+
{"version":3,"file":"buildAction.js","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/build.ts","../../src/cli/buildAction.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types.ts'\nimport type {BuildContext} from './core/contexts/buildContext.ts'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths.ts'\nimport type {DtsTask} from './tasks/dts/types.ts'\nimport type {BuildTask, RolldownDtsTask, RollupTask, RollupTaskEntry} from './tasks/types.ts'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, pkg, target} = ctx\n\n const bundles = config?.bundles || []\n\n const tasks: BuildTask[] = []\n\n const exports: Array<PkgExport & {_path: string}> = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => Object.assign({}, exp, {_path}),\n )\n\n const dtsTask: DtsTask = {\n type: 'build:dts',\n entries: [],\n }\n\n const rolldownDtsTask: Record<string, RolldownDtsTask> = {}\n const rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (ctx.dts === 'rolldown') {\n if (rolldownDtsTask[buildId]) {\n rolldownDtsTask[buildId].entries.push(entry)\n } else {\n rolldownDtsTask[buildId] = {\n type: 'rolldown:dts',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n if (!ctx.emitDeclarationOnly) {\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n }\n\n if (ctx.dts === 'api-extractor') {\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Handle dts tasks for bundles\n for (const bundle of bundles) {\n if (bundle.source?.endsWith('.ts')) {\n // importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`\n // exportPath needs to be the path to the bundle, like `./dist/cli`\n // targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]\n const exportPath = (bundle.import || bundle.require)!.replace(/\\.[mc]?js$/, '')\n const importId = path.join(pkg.name, exportPath)\n\n dtsTask.entries.push({\n importId,\n exportPath,\n sourcePath: bundle.source,\n targetPaths: getTargetPaths(pkg.type, bundle),\n })\n }\n }\n\n // Add dts task\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:node tasks\n for (const exp of exports) {\n const output = exp.node?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'node', {\n path: exp._path,\n source: exp.node?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:node tasks\n for (const exp of exports) {\n const output = exp.node?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'node', {\n path: exp._path,\n source: exp.node?.source || exp.source,\n output,\n })\n }\n\n for (const bundle of bundles) {\n const idx = bundles.indexOf(bundle)\n\n if (bundle.require) {\n addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_cjs_${idx}$$__`,\n source: bundle.source,\n output: bundle.require,\n })\n }\n\n if (bundle.import) {\n addRollupTaskEntry('esm', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_esm_${idx}$$__`,\n source: bundle.source,\n output: bundle.import,\n })\n }\n }\n\n // Perform rolldown dts tasks first, as they have special logic for removing non .d.ts chunks\n tasks.push(...Object.values(rolldownDtsTask))\n // Then run api-extractor tsdoc release tag checking (if rolldown is used for dts bundling, otherwise api-extractor performs both in the build:dts task)\n // @TODO\n // Then run rollup tasks\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport {up as findPkgPath} from 'empathic/package'\nimport {rimraf} from 'rimraf'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {resolveVanillaExtract, resolveVanillaExtractCssName} from './core/config/vanillaExtract.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {writeBundleCssExports} from './core/pkg/writeBundleCssExports.ts'\nimport {createLogger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {resolveBuildTasks} from './resolveBuildTasks.ts'\nimport {createSpinner} from './spinner.ts'\nimport {buildTaskHandlers} from './tasks/index.ts'\nimport {type BuildTask, type TaskHandler} from './tasks/types.ts'\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n clean = false,\n quiet = false,\n } = options\n const logger = createLogger(quiet)\n\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('no package.json found', {cause: {cwd}})\n }\n const config = await loadConfig({cwd, pkgPath})\n\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n if (clean) {\n if (!quiet) {\n logger.log(\n `Deleting the \\`dist\\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,\n )\n }\n await rimraf(ctx.distPath)\n }\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- TypeScript can't infer the correct handler type from discriminated union\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName, quiet)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(cwd, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n\n // In vanilla-extract compat mode, make sure package.json declares the conditional `./<css>`\n // export that the injected `import \"<pkg>/<css>\"` resolves through.\n const vanillaExtract = resolveVanillaExtract(config)\n if (vanillaExtract.compatMode) {\n await writeBundleCssExports({\n cwd,\n distPath: ctx.distPath,\n cssName: resolveVanillaExtractCssName(vanillaExtract.options, {\n compatMode: true,\n runtime: '*',\n }),\n logger,\n })\n }\n}\n","import {build} from '../node/build.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function buildAction(options: {\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n try {\n await build({\n cwd: process.cwd(),\n emitDeclarationOnly: options.emitDeclarationOnly,\n strict: options.strict,\n tsconfig: options.tsconfig,\n clean: options.clean,\n quiet: options.quiet,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"names":["findPkgPath"],"mappings":";;;;;;;;AAQO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,QAAQ,KAAK,OAAA,IAAU,KAExB,UAAU,QAAQ,WAAW,CAAA,GAE7B,QAAqB,CAAA,GAErB,UAA8C,OAAO,QAAQ,IAAI,WAAW,CAAA,CAAE,EAAE;AAAA,IACpF,CAAC,CAAC,OAAO,GAAG,MAAM,OAAO,OAAO,CAAA,GAAI,KAAK,EAAC,MAAA,CAAM;AAAA,EAAA,GAG5C,UAAmB;AAAA,IACvB,MAAM;AAAA,IACN,SAAS,CAAA;AAAA,EAAC,GAGN,kBAAmD,IACnD,cAA0C,CAAA;AAEhD,WAAS,mBAAmB,QAAmB,SAAqB,OAAwB;AAC1F,UAAM,UAAU,GAAG,MAAM,IAAI,OAAO;AAEhC,QAAI,QAAQ,eACV,gBAAgB,OAAO,IACzB,gBAAgB,OAAO,EAAE,QAAQ,KAAK,KAAK,IAE3C,gBAAgB,OAAO,IAAI;AAAA,MACzB,MAAM;AAAA,MACN;AAAA,MACA,SAAS,CAAC,KAAK;AAAA,MACf;AAAA,MACA;AAAA,MACA,QAAQ,OAAO,OAAO;AAAA,IAAA,IAKvB,IAAI,wBACH,YAAY,OAAO,IACrB,YAAY,OAAO,EAAE,QAAQ,KAAK,KAAK,IAEvC,YAAY,OAAO,IAAI;AAAA,MACrB,MAAM;AAAA,MACN;AAAA,MACA,SAAS,CAAC,KAAK;AAAA,MACf;AAAA,MACA;AAAA,MACA,QAAQ,OAAO,OAAO;AAAA,IAAA;AAAA,EAI9B;AAEA,MAAI,IAAI,QAAQ,iBAAiB;AAE/B,eAAW,OAAO,SAAS;AACzB,YAAM,WAAW,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK;AAE1C,UAAI,QAAQ,SAAS,KAAK,KAC5B,QAAQ,QAAQ,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C,SAAS,KAAK;AAGZ,UAFA,QAAQ,SAEJ,eAAe,OAAO;AACxB,cAAM,SAAS,IAAI,OAAO,KAAK,GAAG;AAElC,YAAI,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GACjD,IAAI,OAAO,IAAA;AAAA,MACb;AAEA,cAAQ,MAAM,KAAK,MAAM,GAAG,GAE5B,QAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAIA,QAAM,iBAAiB,sBAAsB,MAAM;AAC/C,iBAAe,cACjB,MAAM,sBAAsB;AAAA,IAC1B;AAAA,IACA,UAAU,IAAI;AAAA,IACd,SAAS,6BAA6B,eAAe,SAAS;AAAA,MAC5D,YAAY;AAAA,MACZ,SAAS;AAAA,IAAA,CACV;AAAA,IACD;AAAA,EAAA,CACD;AAEL;AC7HA,eAAsB,YAAY,SAMhB;AAChB,MAAI;AACF,UAAM,MAAM;AAAA,MACV,KAAK,QAAQ,IAAA;AAAA,MACb,qBAAqB,QAAQ;AAAA,MAC7B,QAAQ,QAAQ;AAAA,MAChB,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,MACf,OAAO,QAAQ;AAAA,IAAA,CAChB;AAAA,EACH,SAAS,KAAK;AACZ,gBAAY,GAAG;AAAA,EACjB;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiExtractorConfig.js","sources":["../../src/node/tasks/dts/createApiExtractorConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'\nimport ts from 'typescript'\n\nexport function createApiExtractorConfig(options: {\n bundledPackages?: string[]\n distPath: string\n exportPath: string\n filePath: string\n messages: IExtractorMessagesConfig\n projectFolder: string\n mainEntryPointFilePath: string\n tsconfig: ts.ParsedCommandLine\n tsconfigPath: string\n dtsRollupEnabled: boolean\n}): IConfigFile {\n const {\n bundledPackages,\n distPath,\n exportPath,\n filePath,\n messages,\n projectFolder,\n mainEntryPointFilePath,\n tsconfig,\n tsconfigPath,\n dtsRollupEnabled,\n } = options\n\n return {\n apiReport: {\n enabled: false,\n reportFileName: '<unscopedPackageName>.api.md',\n },\n bundledPackages,\n\n // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),\n compiler: tsconfig.options.paths\n ? {\n overrideTsconfig: {\n extends: tsconfigPath,\n compilerOptions: {\n // An empty object replaces whatever is in the original tsconfig file\n paths: {},\n },\n },\n }\n : {tsconfigFilePath: tsconfigPath},\n\n docModel: {\n enabled: false,\n apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),\n },\n dtsRollup: {\n enabled: dtsRollupEnabled,\n untrimmedFilePath: path.resolve(distPath, filePath),\n // betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),\n // publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),\n },\n tsdocMetadata: {\n enabled: false,\n },\n messages,\n mainEntryPointFilePath,\n projectFolder,\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createApiExtractorConfig.js","sources":["../../src/node/tasks/dts/createApiExtractorConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'\nimport type ts from '@typescript/typescript6'\n\nexport function createApiExtractorConfig(options: {\n bundledPackages?: string[]\n distPath: string\n exportPath: string\n filePath: string\n messages: IExtractorMessagesConfig\n projectFolder: string\n mainEntryPointFilePath: string\n tsconfig: ts.ParsedCommandLine\n tsconfigPath: string\n dtsRollupEnabled: boolean\n}): IConfigFile {\n const {\n bundledPackages,\n distPath,\n exportPath,\n filePath,\n messages,\n projectFolder,\n mainEntryPointFilePath,\n tsconfig,\n tsconfigPath,\n dtsRollupEnabled,\n } = options\n\n return {\n apiReport: {\n enabled: false,\n reportFileName: '<unscopedPackageName>.api.md',\n },\n bundledPackages,\n\n // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),\n compiler: tsconfig.options.paths\n ? {\n overrideTsconfig: {\n extends: tsconfigPath,\n compilerOptions: {\n // An empty object replaces whatever is in the original tsconfig file\n paths: {},\n },\n },\n }\n : {tsconfigFilePath: tsconfigPath},\n\n docModel: {\n enabled: false,\n apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),\n },\n dtsRollup: {\n enabled: dtsRollupEnabled,\n untrimmedFilePath: path.resolve(distPath, filePath),\n // betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),\n // publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),\n },\n tsdocMetadata: {\n enabled: false,\n },\n messages,\n mainEntryPointFilePath,\n projectFolder,\n }\n}\n"],"names":[],"mappings":";AAIO,SAAS,yBAAyB,SAWzB;AACd,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,SAAO;AAAA,IACL,WAAW;AAAA,MACT,SAAS;AAAA,MACT,gBAAgB;AAAA,IAAA;AAAA,IAElB;AAAA;AAAA,IAGA,UAAU,SAAS,QAAQ,QACvB;AAAA,MACE,kBAAkB;AAAA,QAChB,SAAS;AAAA,QACT,iBAAiB;AAAA;AAAA,UAEf,OAAO,CAAA;AAAA,QAAC;AAAA,MACV;AAAA,IACF,IAEF,EAAC,kBAAkB,aAAA;AAAA,IAEvB,UAAU;AAAA,MACR,SAAS;AAAA,MACT,iBAAiB,KAAK,QAAQ,UAAU,GAAG,UAAU,WAAW;AAAA,IAAA;AAAA,IAElE,WAAW;AAAA,MACT,SAAS;AAAA,MACT,mBAAmB,KAAK,QAAQ,UAAU,QAAQ;AAAA;AAAA;AAAA,IAAA;AAAA,IAIpD,eAAe;AAAA,MACb,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractModuleBlocks.js","sources":["../../src/node/tasks/dts/extractModuleBlocks.ts"],"sourcesContent":["import type {ExtractorResult} from '@microsoft/api-extractor'\nimport ts from 'typescript'\n\n/**\n * A workaround to find all module blocks in extract TS files.\n * @internal\n * */\nexport function extractModuleBlocksFromTypes({\n tsOutDir,\n extractResult,\n}: {\n tsOutDir: string\n extractResult: ExtractorResult\n}): string[] {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ExtractorResult type from @microsoft/api-extractor is complex\n const program = extractResult.compilerState.program as ts.Program\n const moduleBlocks: string[] = []\n\n // all program files, including node_modules\n const allProgramFiles = [...program.getSourceFiles()]\n\n // just our compiled files used in the program\n const sourceFiles = allProgramFiles.filter((sourceFile) => sourceFile.fileName.includes(tsOutDir))\n\n for (const sourceFile of sourceFiles) {\n if (sourceFile.text.includes('declare module')) {\n // Re-parse the source file to ensure we have a complete AST\n // The source files from API Extractor's program may not have fully parsed statements\n const parsedFile = ts.createSourceFile(\n sourceFile.fileName,\n sourceFile.text,\n ts.ScriptTarget.Latest,\n /* setParentNodes */ true,\n )\n moduleBlocks.push(...extractModuleBlocks(parsedFile))\n }\n }\n\n return moduleBlocks\n}\n\n/**\n * Extract `declare module` blocks from a TypeScript source file.\n */\nfunction extractModuleBlocks(sourceFile: ts.SourceFile): string[] {\n const text = sourceFile.text\n const moduleBlocks: string[] = []\n\n const statements = sourceFile.statements\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i]\n if (statement && ts.isModuleDeclaration(statement)) {\n // Get positions for extracting text\n const fullStart = statement.getFullStart()\n const start = statement.getStart(sourceFile)\n let end = statement.getEnd()\n\n // Include trailing comments (like sourceMappingURL)\n // First check for same-line trailing comments\n const trailingComments = ts.getTrailingCommentRanges(text, end)\n const lastTrailing = trailingComments?.at(-1)\n if (lastTrailing) {\n end = lastTrailing.end\n } else {\n // Check for comments on following lines (only if this is the last statement\n // or if they come before the next statement)\n const nextStatement = statements[i + 1]\n const nextStatementStart = nextStatement?.getFullStart() ?? text.length\n const commentsAfter = ts.getLeadingCommentRanges(text, end)\n const lastCommentAfter = commentsAfter?.at(-1)\n if (lastCommentAfter && lastCommentAfter.end <= nextStatementStart) {\n end = lastCommentAfter.end\n }\n }\n\n // Check for leading JSDoc comments\n const leadingComments = ts.getLeadingCommentRanges(text, fullStart)\n\n let blockStart = start\n if (leadingComments && leadingComments.length > 0) {\n // Use the last comment if it's a JSDoc comment (starts with /**)\n const lastComment = leadingComments.at(-1)\n if (lastComment) {\n const commentText = text.slice(lastComment.pos, lastComment.end)\n if (commentText.startsWith('/**')) {\n blockStart = lastComment.pos\n }\n }\n }\n\n // Extract the text from blockStart to end\n // No need to dedent - the output will be formatted by prettier\n moduleBlocks.push(text.slice(blockStart, end))\n }\n }\n\n return moduleBlocks\n}\n"],"names":[],"mappings":";AAOO,SAAS,6BAA6B;AAAA,EAC3C;AAAA,EACA;AACF,GAGa;AAEX,QAAM,UAAU,cAAc,cAAc,SACtC,eAAyB,CAAA,GAMzB,cAHkB,CAAC,GAAG,QAAQ,gBAAgB,EAGhB,OAAO,CAAC,eAAe,WAAW,SAAS,SAAS,QAAQ,CAAC;AAEjG,aAAW,cAAc;AACvB,QAAI,WAAW,KAAK,SAAS,gBAAgB,GAAG;AAG9C,YAAM,aAAa,GAAG;AAAA,QACpB,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAG,aAAa;AAAA;AAAA,QACK;AAAA,MAAA;AAEvB,mBAAa,KAAK,GAAG,oBAAoB,UAAU,CAAC;AAAA,IACtD;AAGF,SAAO;AACT;AAKA,SAAS,oBAAoB,YAAqC;AAChE,QAAM,OAAO,WAAW,MAClB,eAAyB,IAEzB,aAAa,WAAW;AAC9B,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,UAAM,YAAY,WAAW,CAAC;AAC9B,QAAI,aAAa,GAAG,oBAAoB,SAAS,GAAG;AAElD,YAAM,YAAY,UAAU,aAAA,GACtB,QAAQ,UAAU,SAAS,UAAU;AAC3C,UAAI,MAAM,UAAU,OAAA;AAKpB,YAAM,eADmB,GAAG,yBAAyB,MAAM,GAAG,GACvB,GAAG,EAAE;AAC5C,UAAI;AACF,cAAM,aAAa;AAAA,WACd;AAIL,cAAM,qBADgB,WAAW,IAAI,CAAC,GACI,kBAAkB,KAAK,QAE3D,mBADgB,GAAG,wBAAwB,MAAM,GAAG,GAClB,GAAG,EAAE;AACzC,4BAAoB,iBAAiB,OAAO,uBAC9C,MAAM,iBAAiB;AAAA,MAE3B;AAGA,YAAM,kBAAkB,GAAG,wBAAwB,MAAM,SAAS;AAElE,UAAI,aAAa;AACjB,UAAI,mBAAmB,gBAAgB,SAAS,GAAG;AAEjD,cAAM,cAAc,gBAAgB,GAAG,EAAE;AACrC,uBACkB,KAAK,MAAM,YAAY,KAAK,YAAY,GAAG,EAC/C,WAAW,KAAK,MAC9B,aAAa,YAAY;AAAA,MAG/B;AAIA,mBAAa,KAAK,KAAK,MAAM,YAAY,GAAG,CAAC;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"extractModuleBlocks.js","sources":["../../src/node/tasks/dts/extractModuleBlocks.ts"],"sourcesContent":["import type {ExtractorResult} from '@microsoft/api-extractor'\nimport ts from '@typescript/typescript6'\n\n/**\n * A workaround to find all module blocks in extract TS files.\n * @internal\n * */\nexport function extractModuleBlocksFromTypes({\n tsOutDir,\n extractResult,\n}: {\n tsOutDir: string\n extractResult: ExtractorResult\n}): string[] {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ExtractorResult type from @microsoft/api-extractor is complex\n const program = extractResult.compilerState.program as ts.Program\n const moduleBlocks: string[] = []\n\n // all program files, including node_modules\n const allProgramFiles = [...program.getSourceFiles()]\n\n // just our compiled files used in the program\n const sourceFiles = allProgramFiles.filter((sourceFile) => sourceFile.fileName.includes(tsOutDir))\n\n for (const sourceFile of sourceFiles) {\n if (sourceFile.text.includes('declare module')) {\n // Re-parse the source file to ensure we have a complete AST\n // The source files from API Extractor's program may not have fully parsed statements\n const parsedFile = ts.createSourceFile(\n sourceFile.fileName,\n sourceFile.text,\n ts.ScriptTarget.Latest,\n /* setParentNodes */ true,\n )\n moduleBlocks.push(...extractModuleBlocks(parsedFile))\n }\n }\n\n return moduleBlocks\n}\n\n/**\n * Extract `declare module` blocks from a TypeScript source file.\n */\nfunction extractModuleBlocks(sourceFile: ts.SourceFile): string[] {\n const text = sourceFile.text\n const moduleBlocks: string[] = []\n\n const statements = sourceFile.statements\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i]\n if (statement && ts.isModuleDeclaration(statement)) {\n // Get positions for extracting text\n const fullStart = statement.getFullStart()\n const start = statement.getStart(sourceFile)\n let end = statement.getEnd()\n\n // Include trailing comments (like sourceMappingURL)\n // First check for same-line trailing comments\n const trailingComments = ts.getTrailingCommentRanges(text, end)\n const lastTrailing = trailingComments?.at(-1)\n if (lastTrailing) {\n end = lastTrailing.end\n } else {\n // Check for comments on following lines (only if this is the last statement\n // or if they come before the next statement)\n const nextStatement = statements[i + 1]\n const nextStatementStart = nextStatement?.getFullStart() ?? text.length\n const commentsAfter = ts.getLeadingCommentRanges(text, end)\n const lastCommentAfter = commentsAfter?.at(-1)\n if (lastCommentAfter && lastCommentAfter.end <= nextStatementStart) {\n end = lastCommentAfter.end\n }\n }\n\n // Check for leading JSDoc comments\n const leadingComments = ts.getLeadingCommentRanges(text, fullStart)\n\n let blockStart = start\n if (leadingComments && leadingComments.length > 0) {\n // Use the last comment if it's a JSDoc comment (starts with /**)\n const lastComment = leadingComments.at(-1)\n if (lastComment) {\n const commentText = text.slice(lastComment.pos, lastComment.end)\n if (commentText.startsWith('/**')) {\n blockStart = lastComment.pos\n }\n }\n }\n\n // Extract the text from blockStart to end\n // No need to dedent - the output will be form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EjD,cAAM,cAAc,gBAAgB,GAAG,EAAE;AACrC,uBACkB,KAAK,MAAM,YAAY,KAAK,YAAY,GAAG,EAC/C,WAAW,KAAK,MAC9B,aAAa,YAAY;AAAA,MAG/B;AAIA,mBAAa,KAAK,KAAK,MAAM,YAAY,GAAG,CAAC;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;"}
|
package/dist/_chunks-es/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { printExtractMessages } from "./printExtractMessages.js";
|
|
|
7
7
|
import { ExtractorConfig, Extractor, ExtractorLogLevel } from "@microsoft/api-extractor";
|
|
8
8
|
import * as rimraf from "rimraf";
|
|
9
9
|
import { rimraf as rimraf$1 } from "rimraf";
|
|
10
|
-
import ts from "typescript";
|
|
10
|
+
import ts from "@typescript/typescript6";
|
|
11
11
|
import { mkdirp } from "mkdirp";
|
|
12
12
|
import * as prettier from "prettier";
|
|
13
13
|
import { createApiExtractorConfig } from "./createApiExtractorConfig.js";
|
|
@@ -66,7 +66,7 @@ async function writeBundleCssExports(options) {
|
|
|
66
66
|
}
|
|
67
67
|
function printDiagnostic(options) {
|
|
68
68
|
const { cwd, logger, diagnostic } = options;
|
|
69
|
-
if (diagnostic.file && diagnostic.start) {
|
|
69
|
+
if (diagnostic.file && diagnostic.start !== void 0) {
|
|
70
70
|
const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), message = ts.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
71
71
|
`), file = path.relative(cwd, diagnostic.file.fileName), output = [
|
|
72
72
|
`${chalk.yellow(file)}:${chalk.blue(line + 1)}:${chalk.blue(character + 1)} - `,
|
|
@@ -236,10 +236,11 @@ const dtsTask = {
|
|
|
236
236
|
exec: (ctx, task) => {
|
|
237
237
|
const { config, cwd, files, logger, strict, ts: tsContext, bundledPackages } = ctx;
|
|
238
238
|
return new Observable((observer) => {
|
|
239
|
-
|
|
239
|
+
const { config: tsConfig, configPath: tsConfigPath } = tsContext;
|
|
240
|
+
if (!tsConfig || !tsConfigPath)
|
|
240
241
|
return observer.next({ type: "dts", messages: [], results: [] }), observer.complete(), () => {
|
|
241
242
|
};
|
|
242
|
-
const { outDir, rootDir = cwd } =
|
|
243
|
+
const { outDir, rootDir = cwd } = tsConfig.options;
|
|
243
244
|
if (!outDir)
|
|
244
245
|
return observer.error(new Error("tsconfig.json is missing `compilerOptions.outDir`")), () => {
|
|
245
246
|
};
|
|
@@ -248,22 +249,22 @@ const dtsTask = {
|
|
|
248
249
|
cwd,
|
|
249
250
|
logger,
|
|
250
251
|
outDir: tmpPath,
|
|
251
|
-
tsconfig:
|
|
252
|
+
tsconfig: tsConfig,
|
|
252
253
|
strict,
|
|
253
254
|
checkTypes: config?.extract?.checkTypes
|
|
254
255
|
}).catch((err) => {
|
|
255
256
|
observer.error(err);
|
|
256
257
|
});
|
|
257
258
|
const host = ts.createWatchCompilerHost(
|
|
258
|
-
|
|
259
|
+
tsConfigPath,
|
|
259
260
|
{
|
|
260
|
-
...
|
|
261
|
+
...tsConfig.options,
|
|
261
262
|
declaration: !0,
|
|
262
263
|
declarationDir: tmpPath,
|
|
263
264
|
emitDeclarationOnly: !0,
|
|
264
265
|
noEmit: !1,
|
|
265
|
-
noEmitOnError: strict ? !0 :
|
|
266
|
-
noCheck: config?.extract?.checkTypes === !1 ? !0 :
|
|
266
|
+
noEmitOnError: strict ? !0 : tsConfig.options.noEmitOnError ?? !0,
|
|
267
|
+
noCheck: config?.extract?.checkTypes === !1 ? !0 : tsConfig.options.noCheck ?? tsConfig.options.isolatedDeclarations,
|
|
267
268
|
outDir: tmpPath
|
|
268
269
|
},
|
|
269
270
|
ts.sys,
|
|
@@ -297,9 +298,9 @@ const dtsTask = {
|
|
|
297
298
|
projectPath: cwd,
|
|
298
299
|
rules: config?.extract?.rules,
|
|
299
300
|
sourceTypesPath,
|
|
300
|
-
tsconfig:
|
|
301
|
+
tsconfig: tsConfig,
|
|
301
302
|
tmpPath,
|
|
302
|
-
tsconfigPath: path.resolve(cwd,
|
|
303
|
+
tsconfigPath: path.resolve(cwd, tsConfigPath),
|
|
303
304
|
extractorDisabled: config?.extract?.enabled === !1
|
|
304
305
|
});
|
|
305
306
|
messages.push(...result.messages), results.push({ sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths });
|
|
@@ -492,7 +493,10 @@ function shouldEnableStyledComponents(config, pkg, logger) {
|
|
|
492
493
|
}
|
|
493
494
|
function resolveRollupConfig(ctx, buildTask) {
|
|
494
495
|
const { format, runtime, target } = buildTask, { config, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, outputExt = pkgExtMap[pkg.type || "commonjs"][format], minify = config?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
495
|
-
Object.entries(ts2.config?.options.paths || {}).
|
|
496
|
+
Object.entries(ts2.config?.options.paths || {}).flatMap(([key, val]) => {
|
|
497
|
+
const pathAlias = val[0];
|
|
498
|
+
return pathAlias ? [[key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", pathAlias)]] : [];
|
|
499
|
+
})
|
|
496
500
|
), entries = buildTask.entries.map((entry) => ({
|
|
497
501
|
...entry,
|
|
498
502
|
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|