Skip to content

Commit

Permalink
chore: take a look at swc
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfrancois committed Oct 11, 2023
1 parent cd04f75 commit 8e7d4a6
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 22 deletions.
2 changes: 0 additions & 2 deletions fork/react-bootstrap/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * as bootstrapUtils from './bootstrapUtils';
export createChainedFunction from './createChainedFunction';
export ValidComponentChildren from './ValidComponentChildren';
33 changes: 33 additions & 0 deletions tools/scripts-config-swc/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": true,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"transform": {
"react": {
"runtime": "automatic",
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false
}
},
"target": "es5",
"loose": false,
"externalHelpers": false,
"keepClassNames": false
},
"minify": false
}
24 changes: 24 additions & 0 deletions tools/scripts-config-swc/.swcrc-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": true
},
"transform": {
"react": {
"runtime": "automatic",
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false
}
},
"target": "es5",
"loose": false,
"externalHelpers": false,
"keepClassNames": false
},
"minify": false
}
Empty file.
6 changes: 6 additions & 0 deletions tools/scripts-config-swc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@talend/scripts-config-swc",
"version": "1.0.0",
"description": "Talend scripts config for swc web compiler",
"main": "index.js"
}
2 changes: 2 additions & 0 deletions tools/scripts-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@talend/scripts-config-babel": "^13.0.0",
"@talend/scripts-config-jest": "^12.2.0",
"@talend/scripts-config-typescript": "^11.1.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.92",
"cpx2": "^3.0.2",
"fs-extra": "^10.1.0",
"lodash": "^4.17.21",
Expand Down
15 changes: 10 additions & 5 deletions tools/scripts-core/src/scripts/build-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export default async function build(env, presetApi, unsafeOptions) {
});

const babelRootPath = utils.path.getPkgRootPath('@talend/scripts-config-babel');
const swcRootPath = utils.path.getPkgRootPath('@talend/scripts-config-swc');
const tsRootPath = utils.path.getPkgRootPath('@talend/scripts-config-typescript');
const babelConfigPath =
getUserConfigFile(['.babelrc', '.babelrc.json', 'babel.config.js']) ||
path.join(babelRootPath, '.babelrc.json');
const swcConfigPath =
getUserConfigFile(['.swcrc']) || path.join(swcRootPath, '.swcrc-typescript');
const tscConfigPath =
getUserConfigFile(['tsconfig.build.json', 'tsconfig.json']) ||
path.join(tsRootPath, 'tsconfig.json');
Expand All @@ -44,13 +47,14 @@ export default async function build(env, presetApi, unsafeOptions) {
resolve({ status: 0 });
return;
}
console.log('Compiling with babel...');
console.log('Compiling with swc...', swcConfigPath);
const startTime = Date.now();
const babelSpawn = await utils.process.spawn(
'npx',
[
'babel',
'swc',
'--config-file',
babelConfigPath,
swcConfigPath,
'-d',
targetFolder,
srcFolder,
Expand All @@ -69,11 +73,12 @@ export default async function build(env, presetApi, unsafeOptions) {
},
);
babelSpawn.on('exit', status => {
const endTime = Date.now();
if (parseInt(status, 10) !== 0) {
console.error(`Babel exit error: ${status}`);
console.error(`SWC exit error: ${status}`);
reject(new Error(status));
} else {
console.log(`Babel exit: ${status}`);
console.log(`SWC exit: ${status} in ${endTime - startTime}ms`);
resolve({ status });
}
});
Expand Down
Loading

0 comments on commit 8e7d4a6

Please sign in to comment.