Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions actions/build.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ export class BuildAction extends AbstractAction {
'typeCheck',
commandOptions,
);
if (typeCheck && builder.type !== 'swc') {
if (typeCheck && !['swc', 'oxc'].includes(builder.type)) {
console.warn(
INFO_PREFIX +
` "typeCheck" will not have any effect when "builder" is not "swc".`,
` "typeCheck" will not have any effect when "builder" is not "swc" or "oxc".`,
);
}

Expand Down Expand Up @@ -175,10 +175,53 @@ export class BuildAction extends AbstractAction {
onSuccess,
);
break;
case 'oxc':
await this.runOxc(
configuration,
appName,
pathToTsconfig,
watchMode,
commandOptions,
tsOptions,
onSuccess,
);
break;
}
}
}

private async runOxc(
configuration: Required<Configuration>,
appName: string | undefined,
pathToTsconfig: string,
watchMode: boolean,
options: Input[],
tsOptions: ts.CompilerOptions,
onSuccess: (() => void) | undefined,
) {
const { OxcCompiler } = await import('../lib/compiler/oxc/oxc-compiler');
const oxc = new OxcCompiler(this.pluginsLoader);

await oxc.run(
configuration,
pathToTsconfig,
appName,
{
watch: watchMode,
typeCheck: getValueOrDefault<boolean>(
configuration,
'compilerOptions.typeCheck',
appName,
'typeCheck',
options,
),
tsOptions,
assetsManager: this.assetsManager,
},
onSuccess,
);
}

private async runSwc(
configuration: Required<Configuration>,
appName: string | undefined,
Expand Down Expand Up @@ -220,9 +263,8 @@ export class BuildAction extends AbstractAction {
watchMode: boolean,
onSuccess: (() => void) | undefined,
) {
const { WebpackCompiler } = await import(
'../lib/compiler/webpack-compiler'
);
const { WebpackCompiler } =
await import('../lib/compiler/webpack-compiler');
const webpackCompiler = new WebpackCompiler(this.pluginsLoader);

const webpackPath =
Expand Down
9 changes: 6 additions & 3 deletions commands/build.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export class BuildCommand extends AbstractCommand {
.option('-c, --config [path]', 'Path to nest-cli configuration file.')
.option('-p, --path [path]', 'Path to tsconfig file.')
.option('-w, --watch', 'Run in watch mode (live-reload).')
.option('-b, --builder [name]', 'Builder to be used (tsc, webpack, swc).')
.option(
'-b, --builder [name]',
'Builder to be used (tsc, webpack, swc, oxc).',
)
.option('--watchAssets', 'Watch non-ts (e.g., .graphql) files mode.')
.option(
'--webpack',
'Use webpack for compilation (deprecated option, use --builder instead).',
)
.option('--type-check', 'Enable type checking (when SWC is used).')
.option('--type-check', 'Enable type checking (when SWC or OXC is used).')
.option('--webpackPath [path]', 'Path to webpack configuration.')
.option('--tsc', 'Use typescript compiler for compilation.')
.option(
Expand Down Expand Up @@ -46,7 +49,7 @@ export class BuildCommand extends AbstractCommand {
value: command.webpackPath,
});

const availableBuilders = ['tsc', 'webpack', 'swc'];
const availableBuilders = ['tsc', 'webpack', 'swc', 'oxc'];
if (command.builder && !availableBuilders.includes(command.builder)) {
console.error(
ERROR_PREFIX +
Expand Down
9 changes: 6 additions & 3 deletions commands/start.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class StartCommand extends AbstractCommand {
.option('-c, --config [path]', 'Path to nest-cli configuration file.')
.option('-p, --path [path]', 'Path to tsconfig file.')
.option('-w, --watch', 'Run in watch mode (live-reload).')
.option('-b, --builder [name]', 'Builder to be used (tsc, webpack, swc).')
.option(
'-b, --builder [name]',
'Builder to be used (tsc, webpack, swc, oxc).',
)
.option('--watchAssets', 'Watch non-ts (e.g., .graphql) files mode.')
.option(
'-d, --debug [hostport] ',
Expand All @@ -27,7 +30,7 @@ export class StartCommand extends AbstractCommand {
'Use webpack for compilation (deprecated option, use --builder instead).',
)
.option('--webpackPath [path]', 'Path to webpack configuration.')
.option('--type-check', 'Enable type checking (when SWC is used).')
.option('--type-check', 'Enable type checking (when SWC or OXC is used).')
.option('--tsc', 'Use typescript compiler for compilation.')
.option(
'--sourceRoot [sourceRoot]',
Expand Down Expand Up @@ -104,7 +107,7 @@ export class StartCommand extends AbstractCommand {
value: command.envFile,
});

const availableBuilders = ['tsc', 'webpack', 'swc'];
const availableBuilders = ['tsc', 'webpack', 'swc', 'oxc'];
if (command.builder && !availableBuilders.includes(command.builder)) {
console.error(
ERROR_PREFIX +
Expand Down
62 changes: 62 additions & 0 deletions lib/compiler/defaults/oxc-defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as ts from 'typescript';
import { Configuration } from '../../configuration';

export const oxcDefaultsFactory = (
tsOptions?: ts.CompilerOptions,
configuration?: Configuration,
) => {
const builderOptions =
typeof configuration?.compilerOptions?.builder !== 'string' &&
configuration?.compilerOptions?.builder?.type === 'oxc'
? configuration.compilerOptions.builder.options || {}
: {};

const { transformOptions: userTransformOptions, ...cliBuilderOptions } =
builderOptions;

const useDefineForClassFields = tsOptions?.useDefineForClassFields ?? false;

return {
transformOptions: {
cwd: process.cwd(),
sourceType: 'unambiguous' as const,
target: 'es2021',
sourcemap: !!(tsOptions?.sourceMap || tsOptions?.inlineSourceMap),
assumptions: {
setPublicClassFields: !useDefineForClassFields,
},
typescript: {
allowNamespaces: true,
removeClassFieldsWithoutInitializer: !useDefineForClassFields,
},
decorator: {
legacy: tsOptions?.experimentalDecorators ?? true,
emitDecoratorMetadata: tsOptions?.emitDecoratorMetadata ?? true,
},
...userTransformOptions,
},
cliOptions: {
outDir: tsOptions?.outDir ? convertPath(tsOptions.outDir) : 'dist',
filenames: [configuration?.sourceRoot ?? 'src'],
extensions: ['.js', '.ts'],
quiet: false,
watch: false,
declaration: false,
inlineSourceMap: !!tsOptions?.inlineSourceMap,
rootDir: tsOptions?.rootDir,
stripLeadingPaths: !tsOptions?.rootDir,
...cliBuilderOptions,
},
};
};

/**
* Converts Windows specific file paths to posix.
* @param windowsPath
*/
function convertPath(windowsPath: string) {
return windowsPath
.replace(/^\\\\\?\\/, '')
.replace(/\\/g, '/')
.replace(/\/\/+/g, '/');
}
1 change: 1 addition & 0 deletions lib/compiler/oxc/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const OXC_LOG_PREFIX = 'OXC';
Loading