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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* *BREAKING* bump `@folio/stripes-webpack` to `6.0.0`.
* *BREAKING* bump `@folio/eslint-config-stripes` to `8.0.0`.
* Loosen GA workflow dependency to `@1` for `^1.0.0` compatibility. Refs STCLI-266.
* *BREAKING* Correctly implement `transpile`. Refs STCLI-259.

## [3.2.0](https://github.com/folio-org/stripes-cli/tree/v3.2.0) (2024-10-09)
[Full Changelog](https://github.com/folio-org/stripes-cli/compare/v3.1.0...v3.2.0)
Expand Down
22 changes: 22 additions & 0 deletions lib/commands/transpile-babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"presets": [
["@babel/preset-env", {
"targets": "> 0.25%, not dead",
"exclude": ["transform-dynamic-import"]
}],
["@babel/preset-flow", { "all": true }],
["@babel/preset-react", { "runtime": "automatic" }],
["@babel/preset-typescript"]
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-transform-class-properties", { "loose": true }],
["@babel/plugin-transform-private-methods", { "loose": true }],
["@babel/plugin-transform-private-property-in-object", { "loose": true }],
"@babel/plugin-transform-export-namespace-from",
"@babel/plugin-proposal-function-sent",
"@babel/plugin-transform-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-syntax-import-meta"
]
}
73 changes: 37 additions & 36 deletions lib/commands/transpile.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
const importLazy = require('import-lazy')(require);
const path = require('node:path');
const { spawn } = require('node:child_process');

const { contextMiddleware } = importLazy('../cli/context-middleware');
const StripesCore = importLazy('../cli/stripes-core');
const StripesPlatform = importLazy('../platform/stripes-platform');
const { stripesConfigFile } = importLazy('./common-options');
const { processError, processStats } = importLazy('../webpack-common');

let _stripesPlatform;
let _stripesCore;

// stripesPlatform and stripesCore overrides primarily used as injection for unit tests
function stripesOverrides(stripesPlatform, stripesCore) {
_stripesPlatform = stripesPlatform;
_stripesCore = stripesCore;
}

/**
* transpile
* @param {object} argv arguments parsed by yargs
*/
function transpileCommand(argv) {
const context = argv.context;
// Default transpile command to production env
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}

const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv);
const webpackOverrides = [];

if (argv.analyze) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line
webpackOverrides.push((config) => {
config.plugins.push(new BundleAnalyzerPlugin());
return config;
});
}

console.info('Transpiling...');
const stripes = _stripesCore || new StripesCore(context, platform.aliases);
stripes.api.transpile(Object.assign({}, argv, { webpackOverrides }))
.then(processStats)
.catch(processError);

const transpile = spawn('babel', [
argv.files,
'--ignore', `dist,node_modules,.storybook,karma.conf.js,jest.config.js,test,tests,${argv.files}/**/tests,${argv.files}/**/*.test.js`,
'-d', 'dist', // output directory
'-s', // include sourcemaps
'-D', // copy over non-compilable files
'--delete-dir-on-start', // clean
'--no-copy-ignored', // don't copy ignored files
'--config-file', `${__dirname}${path.sep}transpile-babel.config.json`,
]);

transpile.stdout.on('data', (data) => {
console.log(`${data}`);
});

transpile.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});

// transpile.on('close', (code) => {
// console.log(`child process exited with code ${code}`);
// });
}

module.exports = {
Expand All @@ -48,13 +48,14 @@ module.exports = {
.middleware([
contextMiddleware(),
])
.positional('configFile', stripesConfigFile.configFile)
.option('analyze', {
describe: 'Run the Webpack Bundle Analyzer after build (launches in browser)',
type: 'boolean',
})
.example('$0 transpile', 'Transpile a module');
.example('$0 transpile --files <path>', 'Transpile files in <path>');
yargs.option('files', {
describe: 'Path to directory containing files to transpile',
type: 'string',
default: './src',
});

return yargs;
},
handler: transpileCommand,
stripesOverrides,
};
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
"docs": "node ./lib/doc/generator"
},
"dependencies": {
"@babel/cli": "^7.26.4",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-class-properties": "^7.0.0",
"@babel/plugin-transform-dynamic-import": "^7.25.9",
"@babel/plugin-transform-export-namespace-from": "^7.0.0",
"@babel/plugin-transform-numeric-separator": "^7.0.0",
"@babel/plugin-transform-private-methods": "^7.18.6",
"@babel/plugin-transform-private-property-in-object": "^7.21.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-flow": "^7.25.9",
"@babel/preset-react": "^7.26.3",
"@babel/preset-typescript": "^7.26.0",
"@babel/register": "^7.25.9",
"@folio/stripes-testing": "^3.0.0",
"@folio/stripes-webpack": "^6.0.0",
"@formatjs/cli": "^6.1.3",
Expand Down
Loading