chore: introduce linaria-scripts (SWC)
Motivation
Upgrading linaria to use modern tooling. This is what you should pay attention for while reviewing this PR: https://github.com/callstack/linaria/pull/1131/files#diff-df46b0b81d593e59747fa15f319c82ed21bb76d5c6a7c91ce670a027904bcdd0
Summary
Implmeneted custom build script based on SWC. Inspired by astro-scripts.. SWC builds ~10x faster than babel. However, most of build time is consumed by typescript compilier. I combined TSC and SWC compilier in one script to save time on unwatned spawning of new processes.
Also, changed all output to /dist, (/dist/cjs, /dist/esm, /dist/types) because I believe it's more convinient way to manage output artifacts. TODO: I also suggest to change output file extensions: .mjs for esm and .cjs for cjs output. I think it's generally good practice.
Almost all tests are passing, however, related to processing expression from imported dependencies are failing, because @linaria/shaker can't understand export syntax of some files (especially @linaria/utils/index.js). Compare Babel exports:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
asyncResolveFallback: true,
syncResolve: true,
collectExportsAndImports: true,
findIdentifiers: true,
nonType: true,
getFileIdx: true,
isExports: true,
isNotNull: true,
isRemoved: true,
isRequire: true,
isTypedNode: true,
isUnnecessaryReactCall: true,
slugify: true,
JSXElementsRemover: true
};
Object.defineProperty(exports, "JSXElementsRemover", {
enumerable: true,
get: function () {
return _JSXElementsRemover.default;
}
});
// ....
and SWC exports:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
asyncResolveFallback: ()=>_asyncResolveFallback.default,
syncResolve: ()=>_asyncResolveFallback.syncResolve,
collectExportsAndImports: ()=>_collectExportsAndImports.default,
findIdentifiers: ()=>_findIdentifiers.default,
nonType: ()=>_findIdentifiers.nonType,
getFileIdx: ()=>_getFileIdx.default,
isExports: ()=>_isExports.default,
isNotNull: ()=>_isNotNull.default,
isRemoved: ()=>_isRemoved.default,
isRequire: ()=>_isRequire.default,
isTypedNode: ()=>_isTypedNode.default,
isUnnecessaryReactCall: ()=>_isUnnecessaryReactCall.default,
slugify: ()=>_slugify.default,
JSXElementsRemover: ()=>_jsxelementsRemover.default
});
I identified out cause of fail. File processed by babel and loaded by import-exports collector:
linaria:shaker:00003 [start] /home/foxpro/Desktop/oss/linaria/packages/utils/dist/cjs/index.js, onlyExports: slugify
linaria:shaker:00003 [import-and-exports] imports: 17 (side-effects: 0), exports: 17, reexports: 0
linaria:shaker:00003 [end] remaining imports: Map(1) { './slugify' => [ 'default' ] }ss
Same file processed by SWC:
2022-11-23T10:40:21.116Z linaria:shaker:00003 [start] /home/foxpro/Desktop/oss/linaria/packages/utils/dist/cjs/index.js, onlyExports: slugify
2022-11-23T10:40:21.121Z linaria:shaker:00003 [import-and-exports] imports: 13 (side-effects: 0), exports: 0, reexports: 0
2022-11-23T10:40:21.128Z linaria:shaker:00003 [end] remaining imports: Map(11) {
'./asyncResolveFallback' => [ 'default', 'syncResolve' ],
'./findIdentifiers' => [ 'default', 'nonType' ],
'./getFileIdx' => [ 'default' ],
'./isExports' => [ 'default' ],
'./isNotNull' => [ 'default' ],
'./isRemoved' => [ 'default' ],
'./isRequire' => [ 'default' ],
'./isTypedNode' => [ 'default' ],
'./isUnnecessaryReactCall' => [ 'default' ],
'./slugify' => [ 'default' ],
'./visitors/JSXElementsRemover' => [ 'default' ]
}
Test plan
Write test for different bundlers I suppose?... Or change library architecture.
This depends on: https://github.com/callstack/linaria/pull/1128
⚠️ No Changeset found
Latest commit: cabd81ed9b25e397ab0b4d04dd34b8ac394c4982
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR