-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): scripts and generator updates to enable SWC transpilatio…
…n for v9 packages (#26527) * chore: add swc/cli as dev dep * feat(migrate-converged-pkg): implement setup to add swcrc config file * feat(scripts): add swc.ts file which runs SWC CLI * feat(scripts): add just-script preset build:react-components to be used by v9 packages to transpile based on browser matrix * feat(migrate-converged-pkg): setup just config file to map just-scripts build to new build:react-components task * test(migrate-converged-pkg): add test cases for added behaviors * fix: deduplicate graceful-fs * fix: deduplicate semver * fix(migrate-converged-pkg): add justConfig to projectConfig paths * feat: simplify v9 compilation flow with swc * fixup! feat: simplify v9 compilation flow with swc * fixup! fixup! feat: simplify v9 compilation flow with swc * chore: update yarn.lock * nit: remove unintended prettier changes * fix: use babel-plugin-module-resolver version 4.1.0 which works with node 14 and above * chore: manually dedupe resolve package * chore: add .swcrc to files v-build owns * chore: cleanup just preset.ts of unused code * chore: cleanup commented out code * chore: update yarn.lock after master merge * feat: add monorepo root .babelrc-v9.json file and update migrate-converged-pkg generator to EXTEND that file within each respective v9 babelrc.json file * chore: update yarn.lock * fix(migrate-converged-generator): add react useBuiltIns config to swcrc to reduce bundle size * test(migrate-converged): update test * chore: add bugfixes: true to swcrc file to suppress bundle size increase caused by rest parameters being buggy in safari * nit: remove ecma target from swcrc since it does nothing, browserlist targets always take precedence * nit: use optional chaining instead of bang operator for just config task * chore: add runtime:classic to swcrc * test: update test to reflect swcrc addition * fix: replace useBuiltIns with useSpread to spread react props instead of using Object.assign --------- Co-authored-by: Martin Hochel <[email protected]>
- Loading branch information
1 parent
a1e3381
commit ea12408
Showing
12 changed files
with
879 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@griffel", | ||
{ | ||
"babelOptions": { | ||
"plugins": [ | ||
[ | ||
"babel-plugin-module-resolver", | ||
{ | ||
"root": ["../../../"], | ||
"alias": { | ||
"@fluentui/tokens": "packages/tokens/lib/index.js", | ||
"^@fluentui/(?!react-icons)(.+)": "packages/react-components/\\1/lib/index.js" | ||
} | ||
} | ||
] | ||
] | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
|
||
import { series } from 'just-scripts'; | ||
|
||
import { apiExtractor } from './api-extractor'; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
export function generateApi() { | ||
return series(generateTypeDeclarations, apiExtractor); | ||
} | ||
|
||
function generateTypeDeclarations() { | ||
const cmd = 'tsc -p ./tsconfig.lib.json --emitDeclarationOnly'; | ||
return execAsync(cmd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
|
||
import type { Options as SwcOptions } from '@swc/core'; | ||
import { logger } from 'just-scripts'; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
type Options = SwcOptions & { module: { type: 'es6' | 'commonjs' | 'amd' } }; | ||
|
||
function swcCli(options: Options) { | ||
const { outputPath, module } = options; | ||
const swcCliBin = 'npx swc'; | ||
const sourceDirMap = { | ||
es6: 'src', | ||
commonjs: 'lib', | ||
amd: 'lib', | ||
}; | ||
const sourceDir = sourceDirMap[options.module.type]; | ||
|
||
const cmd = `${swcCliBin} ${sourceDir} --out-dir ${outputPath} --config module.type=${module?.type}`; | ||
logger.info(`Running swc CLI: ${cmd}`); | ||
|
||
return execAsync(cmd); | ||
} | ||
|
||
export const swc = { | ||
commonjs: () => { | ||
const options: Options = { | ||
configFile: true, | ||
outputPath: 'lib-commonjs', | ||
module: { type: 'commonjs' }, | ||
}; | ||
|
||
return swcCli(options); | ||
}, | ||
esm: () => { | ||
const options: Options = { | ||
configFile: true, | ||
outputPath: 'lib', | ||
module: { type: 'es6' }, | ||
}; | ||
|
||
return swcCli(options); | ||
}, | ||
amd: () => { | ||
const options: Options = { | ||
configFile: true, | ||
outputPath: 'lib-amd', | ||
module: { type: 'amd' }, | ||
}; | ||
|
||
return swcCli(options); | ||
}, | ||
}; |
Oops, something went wrong.