Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: introduce linaria-scripts (SWC) #1131

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrFoxPro
Copy link
Contributor

@MrFoxPro MrFoxPro commented Nov 23, 2022

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: #1128

@changeset-bot
Copy link

changeset-bot bot commented Nov 23, 2022

⚠️ No Changeset found

Latest commit: cabd81e

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

@@ -38,6 +38,7 @@
"husky": "^1.3.1",
"jest": "^28.1.0",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.3.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have syncpack for linting and syncing package-files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants