diff --git a/.changeset/friendly-radios-walk.md b/.changeset/friendly-radios-walk.md new file mode 100644 index 00000000..8f06c9cd --- /dev/null +++ b/.changeset/friendly-radios-walk.md @@ -0,0 +1,5 @@ +--- +'@ice/pkg': minor +--- + +feat: add oxc-transform as optional declaration generator diff --git a/packages/pkg/package.json b/packages/pkg/package.json index 1189fc36..1c74a462 100644 --- a/packages/pkg/package.json +++ b/packages/pkg/package.json @@ -59,9 +59,11 @@ "es-toolkit": "^1.32.0", "figures": "^6.1.0", "fs-extra": "^10.0.0", + "get-tsconfig": "^4.13.0", "globby": "^11.0.4", "gzip-size": "^7.0.0", "magic-string": "^0.25.7", + "oxc-transform": "~0.89.0", "picocolors": "^1.0.0", "postcss": "^8.4.31", "postcss-plugin-rpx2vw": "^1.0.0", diff --git a/packages/pkg/src/config/schema.ts b/packages/pkg/src/config/schema.ts index 30cbf2e5..6ea4ae21 100644 --- a/packages/pkg/src/config/schema.ts +++ b/packages/pkg/src/config/schema.ts @@ -47,8 +47,9 @@ export const userConfigSchema = z.object({ z.boolean(), z.object({ outputMode: z.enum(['multi', 'unique']).optional(), + generator: z.enum(['tsc', 'oxc']).optional(), }), ]), }); -export type UserConfig = z.infer; +export type UserConfigSchemaType = z.infer; diff --git a/packages/pkg/src/core/init.ts b/packages/pkg/src/core/init.ts index bc02501d..318fccdc 100644 --- a/packages/pkg/src/core/init.ts +++ b/packages/pkg/src/core/init.ts @@ -3,7 +3,7 @@ import { formatEntry, getTransformDefaultOutputDir } from '../helpers/getTaskIO. import getDefaultDefineValues from '../helpers/getDefaultDefineValues.js'; import { stringifyObject } from '../utils.js'; import { merge, mergeWith, omit } from 'es-toolkit/object'; -import path from 'node:path'; +import path, { resolve } from 'node:path'; import { groupBy } from 'es-toolkit'; const mergeDefaults: typeof merge = (target, source) => { @@ -27,6 +27,7 @@ const defaultBundleUserConfig: BundleUserConfig = { const defaultDeclarationUserConfig = { outputMode: 'multi', + generator: 'tsc', } satisfies DeclarationUserConfig; export function initContextTasks(ctx: Context) { @@ -103,6 +104,8 @@ export function initTask(buildTask: BuildTask, options: InitTaskOptions) { config.cssMinify = cssMinify; config.outputDir ??= pkg?.outputDir ?? bundleConfig.outputDir ?? defaultBundleUserConfig.outputDir; + // resolve to absolute + config.outputDir = resolve(rootDir, config.outputDir!); if (pkg) { mergeDefaults(config, omit(pkg, ['id', 'pluginInfos', 'id', 'target', 'module', 'declaration', 'outputDir'])); @@ -112,6 +115,7 @@ export function initTask(buildTask: BuildTask, options: InitTaskOptions) { } else if (config.type === 'transform') { config.modes ??= [expectedMode]; config.outputDir ??= pkg?.outputDir ?? getTransformDefaultOutputDir(rootDir, taskName, config); + config.outputDir = resolve(rootDir, config.outputDir!); } else if (config.type === 'declaration') { // should run in initDeclarationTask } else { @@ -136,10 +140,14 @@ export function initDeclarationTask(buildTask: BuildTask, options: InitTaskOptio throw new Error('Cannot disable declaration when transform formats is not empty.'); } initSharedTask(buildTask, options); - config.outputMode ??= - declarationConfig === true - ? defaultDeclarationUserConfig.outputMode - : (declarationConfig?.outputMode ?? defaultDeclarationUserConfig.outputMode); + + if (declarationConfig === true) { + mergeDefaults(config, defaultDeclarationUserConfig); + } else { + config.outputMode ??= declarationConfig?.outputMode ?? defaultDeclarationUserConfig.outputMode; + config.generator ??= declarationConfig?.generator ?? defaultDeclarationUserConfig.generator; + } + const allOutputDirs = allTasks .map((v) => { return v.config.type === 'transform' ? v.config.outputDir! : ''; diff --git a/packages/pkg/src/helpers/dts.ts b/packages/pkg/src/helpers/dts.ts index 60e4d389..051a2b07 100644 --- a/packages/pkg/src/helpers/dts.ts +++ b/packages/pkg/src/helpers/dts.ts @@ -1,4 +1,3 @@ -import ts from 'typescript'; import { consola } from 'consola'; import { normalizePath } from '../utils.js'; import { TaskConfig } from '../types.js'; @@ -6,6 +5,8 @@ import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias'; import fse from 'fs-extra'; import * as path from 'path'; import { merge } from 'es-toolkit/object'; +import { getTsconfig, TsConfigJson } from 'get-tsconfig'; +import type ts from 'typescript'; export type FileExt = 'js' | 'ts' | 'tsx' | 'jsx' | 'cjs' | 'mjs' | 'mts' | 'cts'; @@ -45,6 +46,7 @@ export interface DtsCompileOptions { alias: TaskConfig['alias']; rootDir: string; outputDir: string; + usingOxc: boolean; } function formatAliasToTSPathsConfig(alias: TaskConfig['alias']) { @@ -71,46 +73,39 @@ function addWildcard(str: string) { return `${str.endsWith('/') ? str : `${str}/`}*`; } -async function getTSConfig(rootDir: string, outputDir: string, alias: TaskConfig['alias']) { - const defaultTSCompilerOptions: ts.CompilerOptions = { - allowJs: true, - declaration: true, - emitDeclarationOnly: true, - incremental: true, - skipLibCheck: true, - paths: formatAliasToTSPathsConfig(alias), // default add alias to paths - }; - const projectTSConfig = await getProjectTSConfig(rootDir); - const tsConfig: ts.ParsedCommandLine = merge(merge({ options: defaultTSCompilerOptions }, projectTSConfig), { - options: { - outDir: outputDir, - rootDir: path.join(rootDir, 'src'), - }, - }); - - return tsConfig; -} - -async function getProjectTSConfig(rootDir: string): Promise { - const tsconfigPath = ts.findConfigFile(rootDir, ts.sys.fileExists); - if (tsconfigPath) { - const tsconfigFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); - return ts.parseJsonConfigFileContent(tsconfigFile.config, ts.sys, path.dirname(tsconfigPath)); - } - - return { - options: {}, - fileNames: [], - errors: [], - }; -} - -export async function dtsCompile({ files, rootDir, outputDir, alias }: DtsCompileOptions): Promise { +export async function dtsCompile({ + files, + rootDir, + outputDir, + alias, + usingOxc, +}: DtsCompileOptions): Promise { if (!files.length) { return []; } - const tsConfig = await getTSConfig(rootDir, outputDir, alias); + const projectTSConfigResult = getTsconfig(rootDir); + + const defaultTSConfig: TsConfigJson = { + compilerOptions: { + allowJs: true, + declaration: true, + emitDeclarationOnly: true, + incremental: true, + skipLibCheck: true, + paths: formatAliasToTSPathsConfig(alias), // default add alias to paths + }, + }; + + const tsConfig: TsConfigJson = merge( + projectTSConfigResult ? merge(defaultTSConfig, projectTSConfigResult.config) : defaultTSConfig, + { + compilerOptions: { + outDir: outputDir, + rootDir: path.join(rootDir, 'src'), + }, + }, + ); const _files = files .map((file) => normalizeDtsInput(file, rootDir, outputDir)) @@ -121,28 +116,73 @@ export async function dtsCompile({ files, rootDir, outputDir, alias }: DtsCompil dtsPath: normalizePath(dtsPath), })); + const compileFunction = usingOxc ? compileFromOxc : compileFromTsc; + const dtsFiles = await compileFunction(_files, tsConfig, projectTSConfigResult?.path); + + if (!alias || !Object.keys(alias).length) { + // no alias config + return _files.map((file) => ({ + ...file, + dtsContent: dtsFiles[file.dtsPath], + })); + } + + // We use tsc-alias to resolve d.ts alias. + // Reason: https://github.com/microsoft/TypeScript/issues/30952#issuecomment-1114225407 + const tsConfigLocalPath = path.join(rootDir, 'node_modules/.cache/ice-pkg/tsconfig.json'); + await fse.ensureFile(tsConfigLocalPath); + await fse.writeJSON(tsConfigLocalPath, tsConfig, { spaces: 2 }); + + const runFile = await prepareSingleFileReplaceTscAliasPaths({ + configFile: tsConfigLocalPath, + outDir: outputDir, + }); + + const result = _files.map((file) => ({ + ...file, + dtsContent: dtsFiles[file.dtsPath] ? runFile({ fileContents: dtsFiles[file.dtsPath], filePath: file.dtsPath }) : '', + })); + + return result; +} + +async function compileFromTsc( + files: DtsInputFile[], + tsConfig: TsConfigJson, + configPath?: string, +): Promise> { // In order to only include the update files instead of all the files in the watch mode. function getProgramRootNames(originalFilenames: string[]) { // Should include all the resolved .d.ts file to avoid dts generate error: // TS4025: Exported variable '' has or is using private name ''. const dtsFilenames = originalFilenames.filter((filename) => filename.endsWith('.d.ts')); - const needCompileFileNames = _files.map(({ filePath }) => filePath); + const needCompileFileNames = files.map(({ filePath }) => filePath); return [...needCompileFileNames, ...dtsFilenames]; } + const ts = await import('typescript'); + + const parsedTsConfig: ts.ParsedCommandLine = configPath + ? ts.parseJsonConfigFileContent(tsConfig, ts.sys, configPath) + : ({ + ...tsConfig, + options: tsConfig.compilerOptions, + } as ts.ParsedCommandLine); + + const host = ts.createCompilerHost(parsedTsConfig.options); + const dtsFiles: Record = {}; - const host = ts.createCompilerHost(tsConfig.options); host.writeFile = (fileName, contents) => { dtsFiles[fileName] = contents; }; const programOptions: ts.CreateProgramOptions = { - rootNames: getProgramRootNames(tsConfig.fileNames), - options: tsConfig.options, + rootNames: getProgramRootNames(parsedTsConfig.fileNames), + options: parsedTsConfig.options, host, - projectReferences: tsConfig.projectReferences, - configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(tsConfig), + projectReferences: parsedTsConfig.projectReferences, + configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(parsedTsConfig), }; const program = ts.createProgram(programOptions); @@ -160,36 +200,27 @@ export async function dtsCompile({ files, rootDir, outputDir, alias }: DtsCompil }); } - if (!alias || !Object.keys(alias).length) { - // no alias config - return _files.map((file) => ({ - ...file, - dtsContent: dtsFiles[file.dtsPath], - })); - } - - // We use tsc-alias to resolve d.ts alias. - // Reason: https://github.com/microsoft/TypeScript/issues/30952#issuecomment-1114225407 - const tsConfigLocalPath = path.join(rootDir, 'node_modules/.cache/ice-pkg/tsconfig.json'); - await fse.ensureFile(tsConfigLocalPath); - await fse.writeJSON( - tsConfigLocalPath, - { - ...tsConfig, - compilerOptions: tsConfig.options, - }, - { spaces: 2 }, - ); + return dtsFiles; +} - const runFile = await prepareSingleFileReplaceTscAliasPaths({ - configFile: tsConfigLocalPath, - outDir: outputDir, - }); +async function compileFromOxc( + absFiles: DtsInputFile[], + tsConfig: TsConfigJson, + configPath?: string, +): Promise> { + if (!tsConfig?.compilerOptions?.isolatedDeclarations) { + consola.warn(`Enable isolatedDeclarations in tsconfig.json for correct .d.ts file generation`); + } + const oxc = await import('oxc-transform'); + const dtsFiles: Record = {}; + for (const file of absFiles) { + const fileContent = fse.readFileSync(file.filePath, 'utf-8'); + const { code } = oxc.isolatedDeclaration(file.filePath, fileContent, { + sourcemap: false, + }); - const result = _files.map((file) => ({ - ...file, - dtsContent: dtsFiles[file.dtsPath] ? runFile({ fileContents: dtsFiles[file.dtsPath], filePath: file.dtsPath }) : '', - })); + dtsFiles[file.dtsPath] = code; + } - return result; + return dtsFiles; } diff --git a/packages/pkg/src/helpers/getTaskIO.ts b/packages/pkg/src/helpers/getTaskIO.ts index 16a2706b..99681568 100644 --- a/packages/pkg/src/helpers/getTaskIO.ts +++ b/packages/pkg/src/helpers/getTaskIO.ts @@ -1,4 +1,4 @@ -import { isAbsolute, resolve, join } from 'path'; +import { isAbsolute, resolve, join } from 'node:path'; import { TransformTaskConfig } from '../types.js'; export function formatEntry(inputEntry?: string | string[] | Record): Record { diff --git a/packages/pkg/src/tasks/declaration.ts b/packages/pkg/src/tasks/declaration.ts index e1d026e2..4473628f 100644 --- a/packages/pkg/src/tasks/declaration.ts +++ b/packages/pkg/src/tasks/declaration.ts @@ -63,6 +63,7 @@ class DeclarationRunner extends Runner { rootDir: context.buildContext.rootDir, outputDir: buildConfig.outputDir!, alias: buildConfig.alias, + usingOxc: buildConfig.generator === 'oxc', }, ]); diff --git a/packages/pkg/src/types.ts b/packages/pkg/src/types.ts index f93924c5..835fd07d 100644 --- a/packages/pkg/src/types.ts +++ b/packages/pkg/src/types.ts @@ -157,6 +157,14 @@ export interface DeclarationUserConfig { * @default 'multi' */ outputMode?: 'multi' | 'unique'; + + /** + * The generator to generate .d.ts file + * - `'tsc'` use typescript + * - `'oxc'` use oxc-transform to generate isolated declaration + * @default 'tsc' + */ + generator?: 'tsc' | 'oxc'; } export interface PkgUserConfig diff --git a/packages/pkg/tests/core/init.test.ts b/packages/pkg/tests/core/init.test.ts index d8c58de9..5efbc19b 100644 --- a/packages/pkg/tests/core/init.test.ts +++ b/packages/pkg/tests/core/init.test.ts @@ -40,7 +40,7 @@ function bt( format: string, standardFormat: StandardBundleFormatString[], config: Partial, -): _BuildTask { +): BuildTask { return { name: `bundle-${format}`, config: { @@ -53,7 +53,7 @@ function bt( } // Declaration Task -function dt(config: Partial): _BuildTask { +function dt(config: Partial): BuildTask { return { name: `declaration`, config: { @@ -305,7 +305,7 @@ describe('initTask', () => { describe('outputDir', () => { it('use default', () => { const task = initTask(bt('esm', ['esm:es5'], {}), c({})); - expect((task.config as BundleTaskConfig).outputDir).toEqual('dist'); + expect((task.config as BundleTaskConfig).outputDir).toEqual(join(MOCK_ROOT, 'dist')); }); it('userConfig is preset', () => { @@ -317,7 +317,7 @@ describe('initTask', () => { }, }), ); - expect((task.config as BundleTaskConfig).outputDir).toEqual('custom'); + expect((task.config as BundleTaskConfig).outputDir).toEqual(join(MOCK_ROOT, 'custom')); }); it('taskConfig is preset', () => { @@ -331,7 +331,7 @@ describe('initTask', () => { }, }), ); - expect((task.config as BundleTaskConfig).outputDir).toEqual('custom1'); + expect((task.config as BundleTaskConfig).outputDir).toEqual(join(MOCK_ROOT, 'custom1')); }); }); @@ -352,8 +352,8 @@ describe('initTask', () => { it('using default', () => { const task = initTask(bt('esm', ['esm:es5'], {}), c({})); - expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify)).toEqual([false, false, false, true]); - expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify)).toEqual([false, false, false, true]); + expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify!)).toEqual([false, false, false, true]); + expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify!)).toEqual([false, false, false, true]); }); it('boolean', () => { @@ -366,8 +366,13 @@ describe('initTask', () => { }, }), ); - expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify)).toEqual([value, value, value, value]); - expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify)).toEqual([ + expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify!)).toEqual([ + value, + value, + value, + value, + ]); + expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify!)).toEqual([ value, value, value, @@ -390,10 +395,10 @@ describe('initTask', () => { }, }), ); - expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify)).toEqual( + expect(minifyFunctionTable((task.config as BundleTaskConfig).jsMinify!)).toEqual( jsValue === undefined ? DEFAULT_TABLE : [jsValue, jsValue, jsValue, jsValue], ); - expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify)).toEqual( + expect(minifyFunctionTable((task.config as BundleTaskConfig).cssMinify!)).toEqual( cssValue === undefined ? DEFAULT_TABLE : [cssValue, cssValue, cssValue, cssValue], ); } @@ -401,7 +406,13 @@ describe('initTask', () => { }); }); - describe.each<[key: keyof BundleUserConfig, defaultValue: any, validValues: any[]]>([ + describe.each< + [ + key: Exclude>, + defaultValue: any, + validValues: any[], + ] + >([ ['polyfill', undefined, [false, 'usage', 'entry']], ['compileDependencies', false, [false, true, ['react']]], ['externals', undefined, [false, { react: 'React' }]], @@ -448,42 +459,73 @@ describe('initTask', () => { describe('declaration', () => { const TASKS = [tt('esm', 'esm:es5', {})]; + it('userConfig is true to use default value', () => { + const task = initDeclarationTask( + dt({}), + c({ + declaration: true, + }), + TASKS, + ); + expect(task.config as DeclarationTaskConfig).toContain({ + outputMode: 'multi', + generator: 'tsc', + }); + }); + describe('outputMode', () => { - it('userConfig is true', () => { + it('using userConfig', () => { const task = initDeclarationTask( dt({}), + c({ + declaration: { + outputMode: 'unique', + }, + }), + TASKS, + ); + expect((task.config as DeclarationTaskConfig).outputMode).toEqual('unique'); + }); + + it('using taskConfig', () => { + const task = initDeclarationTask( + dt({ + outputMode: 'unique', + }), c({ declaration: true, }), TASKS, ); - expect((task.config as DeclarationTaskConfig).outputMode).toEqual('multi'); + expect((task.config as DeclarationTaskConfig).outputMode).toEqual('unique'); }); + }); - it('userConfig is Object', () => { + describe('generator', () => { + it('using userConfig', () => { const task = initDeclarationTask( dt({}), c({ declaration: { - outputMode: 'unique', + generator: 'oxc', }, }), TASKS, ); - expect((task.config as DeclarationTaskConfig).outputMode).toEqual('unique'); + expect((task.config as DeclarationTaskConfig).generator).toEqual('oxc'); }); - it('taskConfig is present', () => { + it('using taskConfigValue', () => { const task = initDeclarationTask( dt({ - outputMode: 'unique', + generator: 'oxc', }), c({ declaration: true, }), TASKS, ); - expect((task.config as DeclarationTaskConfig).outputMode).toEqual('unique'); + expect((task.config as DeclarationTaskConfig).generator).toEqual('oxc'); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index db7f320e..261fe519 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -76,7 +76,7 @@ importers: version: 3.0.2 ts-node: specifier: ^10.8.2 - version: 10.8.2(@swc/core@1.13.5(@swc/helpers@0.5.17))(@types/node@17.0.45)(typescript@5.9.2) + version: 10.8.2(@swc/core@1.13.5)(@types/node@17.0.45)(typescript@5.9.2) typescript: specifier: 'catalog:' version: 5.9.2 @@ -397,6 +397,9 @@ importers: fs-extra: specifier: ^10.0.0 version: 10.1.0 + get-tsconfig: + specifier: ^4.13.0 + version: 4.13.0 globby: specifier: ^11.0.4 version: 11.1.0 @@ -406,6 +409,9 @@ importers: magic-string: specifier: ^0.25.7 version: 0.25.9 + oxc-transform: + specifier: ~0.89.0 + version: 0.89.0 picocolors: specifier: ^1.0.0 version: 1.1.1 @@ -1692,6 +1698,15 @@ packages: react: ^16.14.0 || ^17.0.0 || ^18.0.0 react-dom: ^16.14.0 || ^17.0.0 || ^18.0.0 + '@emnapi/core@1.7.0': + resolution: {integrity: sha512-pJdKGq/1iquWYtv1RRSljZklxHCOCAJFJrImO5ZLKPJVJlVUcs8yFwNQlqS0Lo8xT1VAXXTCZocF9n26FWEKsw==} + + '@emnapi/runtime@1.7.0': + resolution: {integrity: sha512-oAYoQnCYaQZKVS53Fq23ceWMRxq5EhQsE0x0RdQ55jT7wagMu5k+fS39v1fiSLrtrLQlXwVINenqhLMtTrV/1Q==} + + '@emnapi/wasi-threads@1.1.0': + resolution: {integrity: sha512-WI0DdZ8xFSbgMjR1sFsKABJ/C5OnRrjT06JXbZKexJGrDuPTzZdDYfFlsgcCXCyf+suG5QU2e/y1Wo2V/OapLQ==} + '@endemolshinegroup/cosmiconfig-typescript-loader@3.0.2': resolution: {integrity: sha512-QRVtqJuS1mcT56oHpVegkKBlgtWjXw/gHNWO3eL9oyB5Sc7HBoc2OLG/nYpVfT/Jejvo3NUrD0Udk7XgoyDKkA==} engines: {node: '>=10.0.0'} @@ -2064,6 +2079,9 @@ packages: '@module-federation/webpack-bundler-runtime@0.14.0': resolution: {integrity: sha512-POWS6cKBicAAQ3DNY5X7XEUSfOfUsRaBNxbuwEfSGlrkTE9UcWheO06QP2ndHi8tHQuUKcIHi2navhPkJ+k5xg==} + '@napi-rs/wasm-runtime@1.0.7': + resolution: {integrity: sha512-SeDnOO0Tk7Okiq6DbXmmBODgOAb9dp9gjlphokTUxmt8U3liIP1ZsozBahH69j/RJv+Rfs6IwUKHTgQYJ/HBAw==} + '@node-rs/jieba-android-arm-eabi@1.6.1': resolution: {integrity: sha512-R1YQfsPr7sK3Tq1sM0//6lNAGJK9RnMT0ShITT+7EJYr5OufUBb38lf/mRhrLxR0NF1pycEsMjdCAwrWrHd8rA==} engines: {node: '>= 10'} @@ -2158,6 +2176,95 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@oxc-transform/binding-android-arm64@0.89.0': + resolution: {integrity: sha512-ClAT3Uwuo++nxwJxKpxiav3jKIRzMSc0mHBoEvBFQgY4rjjwNe13N6ktFwJH6paslQNfJ8NhrzbCgUcj9sFpvQ==} + engines: {node: '>=14.0.0'} + cpu: [arm64] + os: [android] + + '@oxc-transform/binding-darwin-arm64@0.89.0': + resolution: {integrity: sha512-p8ZPY/9A/sbxEZnpFhpFXcmBKESyeGsM+W0uHcP/y2q+esy7aXx4UZlT64zdxqgtepPK7e2LFYYS4RdJTLdM0w==} + engines: {node: '>=14.0.0'} + cpu: [arm64] + os: [darwin] + + '@oxc-transform/binding-darwin-x64@0.89.0': + resolution: {integrity: sha512-GvR99rtmk90Jk9HjxVEHrtndldVaQ2FxJaESzg/zaQaCAN50R1WR8mzfIQN5Pdi5ZFM3dUgxVhVbWmSc6SbpmQ==} + engines: {node: '>=14.0.0'} + cpu: [x64] + os: [darwin] + + '@oxc-transform/binding-freebsd-x64@0.89.0': + resolution: {integrity: sha512-wCNAlWW6ylqQxFFwcOkrQ77HeVaxrsHlKH+POXB1ercbb+OXARhAQaZG7crGGad8RTn1HwkudAl4W7XwcwW8ng==} + engines: {node: '>=14.0.0'} + cpu: [x64] + os: [freebsd] + + '@oxc-transform/binding-linux-arm-gnueabihf@0.89.0': + resolution: {integrity: sha512-7nfOV49v/NsKkcRaMf0RXtnTtYZV+DXgptaBdkGBrqJAtUQ6uvDERJLzRMMiHKfl8qXpvguMjLwCPELDMtLaqA==} + engines: {node: '>=14.0.0'} + cpu: [arm] + os: [linux] + + '@oxc-transform/binding-linux-arm-musleabihf@0.89.0': + resolution: {integrity: sha512-lOSBrPpTTpF2Jr3in2JL4WymKm8V5hPnniVTwhZcpecaBBKmK+qYW88FJJuHkO3uZYx7ZwfkEb0FN7S81hQ2Fw==} + engines: {node: '>=14.0.0'} + cpu: [arm] + os: [linux] + + '@oxc-transform/binding-linux-arm64-gnu@0.89.0': + resolution: {integrity: sha512-fDI14uxb+sm0lcbrRdtm5cvitxNwQ+271hMVqeMm5gUkDCbY0agGvdvbEq/hBuMaMh7BL2uU9fmxOmdRgfmAqg==} + engines: {node: '>=14.0.0'} + cpu: [arm64] + os: [linux] + + '@oxc-transform/binding-linux-arm64-musl@0.89.0': + resolution: {integrity: sha512-9OACjq3oRywMaSW5SQDz6Y2AS62EQ0nkLor7P2YSdnte1LbrciwfqMYm8v6HRJ8Pqif2iqtAc9YlU8OtefSvkA==} + engines: {node: '>=14.0.0'} + cpu: [arm64] + os: [linux] + + '@oxc-transform/binding-linux-riscv64-gnu@0.89.0': + resolution: {integrity: sha512-or2lJ/Uhjaj/Hbz3f741cZM+FKZNwKL20wELOro0xraL7NwThHTHEZGQrSHlJ/VkRdJPuo+UC3xB9OgdY6vvFw==} + engines: {node: '>=14.0.0'} + cpu: [riscv64] + os: [linux] + + '@oxc-transform/binding-linux-s390x-gnu@0.89.0': + resolution: {integrity: sha512-HdC3Z3CTveXgMu13wF6qqjpnH7/Ds9BeOEYU5xGPXAFkTLMxL6miYiLN+kgTekTZeYPphM3Dnx/+Fwrmi1ukDw==} + engines: {node: '>=14.0.0'} + cpu: [s390x] + os: [linux] + + '@oxc-transform/binding-linux-x64-gnu@0.89.0': + resolution: {integrity: sha512-w5xtFpVyUEPo0/gLInZ+NbP5pT6+CG1ukoyZYr3Y+J8cz+xezNokzjeAu4p7MmG6XG63DKBG60dlBVL1HCgtWA==} + engines: {node: '>=14.0.0'} + cpu: [x64] + os: [linux] + + '@oxc-transform/binding-linux-x64-musl@0.89.0': + resolution: {integrity: sha512-MxtHJp0HwH1F6gfAnAtr8W9gD03Hnj9DIlaFcqCXYCEvvzpxo/8kG5E3Y2UCOfR1h2rV2haX4k7+o5Swr+/dMw==} + engines: {node: '>=14.0.0'} + cpu: [x64] + os: [linux] + + '@oxc-transform/binding-wasm32-wasi@0.89.0': + resolution: {integrity: sha512-YPkhOluELfgPgY02RqGwc0Q17HGVNSw3bHJ60pc4IppXAbigXwX+IpWYYowcMtWOr6zAawUAxakUEeLb5yv3pg==} + engines: {node: '>=14.0.0'} + cpu: [wasm32] + + '@oxc-transform/binding-win32-arm64-msvc@0.89.0': + resolution: {integrity: sha512-gsuSbYzBcqfKx7X7c1rZJGskmXDlLMkwm4JmhCVBG91L14j+9eFIOdXk3U6E5/OtiFMtr4WIDlSApEfhDh78Rw==} + engines: {node: '>=14.0.0'} + cpu: [arm64] + os: [win32] + + '@oxc-transform/binding-win32-x64-msvc@0.89.0': + resolution: {integrity: sha512-5HYV5lUVQ/3NJw4QVtgCaPy+6us+YlVxKWE934ulGGlnwZvTgMvsSXiwNdJwkgWhLcfv7Y1NtkFvcMDBi1Gpzg==} + engines: {node: '>=14.0.0'} + cpu: [x64] + os: [win32] + '@pkgr/core@0.2.4': resolution: {integrity: sha512-ROFF39F6ZrnzSUEmQQZUar0Jt4xVoP9WnDRdWwF4NNcXs3xBTLgBUDoOwW141y1jP+S8nahIbdxbFC7IShw9Iw==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -2652,6 +2759,9 @@ packages: '@tsconfig/node16@1.0.3': resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} + '@tybys/wasm-util@0.10.1': + resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==} + '@types/aria-query@5.0.1': resolution: {integrity: sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==} @@ -5047,6 +5157,9 @@ packages: resolution: {integrity: sha512-w9UMqWwJxHNOvoNzSJ2oPF5wvYcvP7jUvYzhp67yEhTi17ZDBBC1z9pTdGuzjD+EFIqLSYRweZjqfiPzQ06Ebg==} engines: {node: '>= 0.4'} + get-tsconfig@4.13.0: + resolution: {integrity: sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==} + git-raw-commits@2.0.11: resolution: {integrity: sha512-VnctFhw+xfj8Va1xtfEqCUD2XDrbAPSJx+hSrE5K7fGdjZruW7XV+QOrN7LF/RJyvspRiD2I0asWsxFp0ya26A==} engines: {node: '>=10'} @@ -6692,6 +6805,10 @@ packages: resolution: {integrity: sha512-qFOyK5PjiWZd+QQIh+1jhdb9LpxTF0qs7Pm8o5QHYZ0M3vKqSqzsZaEB6oWlxZ+q2sJBMI/Ktgd2N5ZwQoRHfg==} engines: {node: '>= 0.4'} + oxc-transform@0.89.0: + resolution: {integrity: sha512-65rusuqi/g5tBB0gcZjM/U9/tSGvaiapus55RXE1AmnTPPEAljSF0z0sm4xDPwCskDPRcvSiJ/cdracCJQ17Sg==} + engines: {node: '>=14.0.0'} + p-cancelable@1.1.0: resolution: {integrity: sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==} engines: {node: '>=6'} @@ -7769,6 +7886,9 @@ packages: resolve-pathname@3.0.0: resolution: {integrity: sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + resolve.exports@2.0.0: resolution: {integrity: sha512-6K/gDlqgQscOlg9fSRpWstA8sYe8rbELsSTNpx+3kTrsVCzvSl0zIvRErM7fdl9ERWDsKnrLnwB+Ne89918XOg==} engines: {node: '>=10'} @@ -11294,6 +11414,22 @@ snapshots: - vue-template-compiler - webpack-cli + '@emnapi/core@1.7.0': + dependencies: + '@emnapi/wasi-threads': 1.1.0 + tslib: 2.8.1 + optional: true + + '@emnapi/runtime@1.7.0': + dependencies: + tslib: 2.8.1 + optional: true + + '@emnapi/wasi-threads@1.1.0': + dependencies: + tslib: 2.8.1 + optional: true + '@endemolshinegroup/cosmiconfig-typescript-loader@3.0.2(cosmiconfig@7.0.1)(typescript@4.9.5)': dependencies: cosmiconfig: 7.0.1 @@ -11770,6 +11906,13 @@ snapshots: '@module-federation/runtime': 0.14.0 '@module-federation/sdk': 0.14.0 + '@napi-rs/wasm-runtime@1.0.7': + dependencies: + '@emnapi/core': 1.7.0 + '@emnapi/runtime': 1.7.0 + '@tybys/wasm-util': 0.10.1 + optional: true + '@node-rs/jieba-android-arm-eabi@1.6.1': optional: true @@ -11837,6 +11980,53 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.13.0 + '@oxc-transform/binding-android-arm64@0.89.0': + optional: true + + '@oxc-transform/binding-darwin-arm64@0.89.0': + optional: true + + '@oxc-transform/binding-darwin-x64@0.89.0': + optional: true + + '@oxc-transform/binding-freebsd-x64@0.89.0': + optional: true + + '@oxc-transform/binding-linux-arm-gnueabihf@0.89.0': + optional: true + + '@oxc-transform/binding-linux-arm-musleabihf@0.89.0': + optional: true + + '@oxc-transform/binding-linux-arm64-gnu@0.89.0': + optional: true + + '@oxc-transform/binding-linux-arm64-musl@0.89.0': + optional: true + + '@oxc-transform/binding-linux-riscv64-gnu@0.89.0': + optional: true + + '@oxc-transform/binding-linux-s390x-gnu@0.89.0': + optional: true + + '@oxc-transform/binding-linux-x64-gnu@0.89.0': + optional: true + + '@oxc-transform/binding-linux-x64-musl@0.89.0': + optional: true + + '@oxc-transform/binding-wasm32-wasi@0.89.0': + dependencies: + '@napi-rs/wasm-runtime': 1.0.7 + optional: true + + '@oxc-transform/binding-win32-arm64-msvc@0.89.0': + optional: true + + '@oxc-transform/binding-win32-x64-msvc@0.89.0': + optional: true + '@pkgr/core@0.2.4': {} '@polka/url@1.0.0-next.21': {} @@ -12272,6 +12462,11 @@ snapshots: '@tsconfig/node16@1.0.3': {} + '@tybys/wasm-util@0.10.1': + dependencies: + tslib: 2.8.1 + optional: true + '@types/aria-query@5.0.1': {} '@types/babel__core@7.1.20': @@ -15107,6 +15302,10 @@ snapshots: es-errors: 1.3.0 get-intrinsic: 1.3.0 + get-tsconfig@4.13.0: + dependencies: + resolve-pkg-maps: 1.0.0 + git-raw-commits@2.0.11: dependencies: dargs: 7.0.0 @@ -15941,7 +16140,7 @@ snapshots: strip-json-comments: 3.1.1 optionalDependencies: '@types/node': 17.0.45 - ts-node: 10.8.2(@swc/core@1.13.5(@swc/helpers@0.5.17))(@types/node@17.0.45)(typescript@5.9.2) + ts-node: 10.8.2(@swc/core@1.13.5)(@types/node@17.0.45)(typescript@5.9.2) transitivePeerDependencies: - supports-color @@ -17056,6 +17255,24 @@ snapshots: object-keys: 1.1.1 safe-push-apply: 1.0.0 + oxc-transform@0.89.0: + optionalDependencies: + '@oxc-transform/binding-android-arm64': 0.89.0 + '@oxc-transform/binding-darwin-arm64': 0.89.0 + '@oxc-transform/binding-darwin-x64': 0.89.0 + '@oxc-transform/binding-freebsd-x64': 0.89.0 + '@oxc-transform/binding-linux-arm-gnueabihf': 0.89.0 + '@oxc-transform/binding-linux-arm-musleabihf': 0.89.0 + '@oxc-transform/binding-linux-arm64-gnu': 0.89.0 + '@oxc-transform/binding-linux-arm64-musl': 0.89.0 + '@oxc-transform/binding-linux-riscv64-gnu': 0.89.0 + '@oxc-transform/binding-linux-s390x-gnu': 0.89.0 + '@oxc-transform/binding-linux-x64-gnu': 0.89.0 + '@oxc-transform/binding-linux-x64-musl': 0.89.0 + '@oxc-transform/binding-wasm32-wasi': 0.89.0 + '@oxc-transform/binding-win32-arm64-msvc': 0.89.0 + '@oxc-transform/binding-win32-x64-msvc': 0.89.0 + p-cancelable@1.1.0: {} p-filter@2.1.0: @@ -18152,6 +18369,8 @@ snapshots: resolve-pathname@3.0.0: {} + resolve-pkg-maps@1.0.0: {} + resolve.exports@2.0.0: {} resolve@1.22.8: @@ -19187,7 +19406,7 @@ snapshots: '@jest/types': 29.4.3 babel-jest: 29.4.3(@babel/core@7.21.3) - ts-node@10.8.2(@swc/core@1.13.5(@swc/helpers@0.5.17))(@types/node@17.0.45)(typescript@5.9.2): + ts-node@10.8.2(@swc/core@1.13.5)(@types/node@17.0.45)(typescript@5.9.2): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.9 diff --git a/tests/integration/default/__snapshots__/index.test.ts.snap b/tests/integration/default/__snapshots__/index.test.ts.snap index b4c77771..9c29bfd9 100644 --- a/tests/integration/default/__snapshots__/index.test.ts.snap +++ b/tests/integration/default/__snapshots__/index.test.ts.snap @@ -111,6 +111,58 @@ exports[`Run config bundle-with-full-modes > es2017 structure 1`] = `null`; exports[`Run config bundle-with-full-modes > esm structure 1`] = `null`; +exports[`Run config declaration-generator-oxc > cjs structure 1`] = `null`; + +exports[`Run config declaration-generator-oxc > dist structure 1`] = `null`; + +exports[`Run config declaration-generator-oxc > es2017 structure 1`] = ` +{ + "files": [ + { + "name": "index.d.ts", + }, + { + "name": "index.js", + }, + ], + "name": "es2017", +} +`; + +exports[`Run config declaration-generator-oxc > esm structure 1`] = ` +{ + "files": [ + { + "name": "index.d.ts", + }, + { + "name": "index.js", + }, + ], + "name": "esm", +} +`; + +exports[`Run config declaration-generator-oxc > file content es2017/index.d.ts 1`] = ` +"export declare const foo = 1; +" +`; + +exports[`Run config declaration-generator-oxc > file content es2017/index.js 1`] = ` +"export const foo = 1; +" +`; + +exports[`Run config declaration-generator-oxc > file content esm/index.d.ts 1`] = ` +"export declare const foo = 1; +" +`; + +exports[`Run config declaration-generator-oxc > file content esm/index.js 1`] = ` +"export var foo = 1; +" +`; + exports[`Run config default > cjs structure 1`] = `null`; exports[`Run config default > dist structure 1`] = `null`; diff --git a/tests/integration/default/index.test.ts b/tests/integration/default/index.test.ts index 4cd11343..3045788e 100644 --- a/tests/integration/default/index.test.ts +++ b/tests/integration/default/index.test.ts @@ -118,4 +118,12 @@ runProjectTest(import.meta.url, [ ], }, }, + { + name: 'declaration-generator-oxc', + config: { + declaration: { + generator: 'oxc', + }, + }, + }, ]);