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

refactor: split one linaria package into multiple @linaria/* #687

Merged
merged 11 commits into from Nov 7, 2020
Merged

Conversation

Anber
Copy link
Collaborator

@Anber Anber commented Oct 28, 2020

Motivation

Closes #413

Summary

The list of packages:

  • @linaria/babel
  • @linaria/cli
  • @linaria/core
  • @linaria/extractor
  • @linaria/logger
  • @linaria/preeval
  • @linaria/react
  • @linaria/rollup
  • @linaria/server
  • @linaria/shaker
  • @linaria/stylelint
  • @linaria/webpack4-loader

@callstack-bot
Copy link

callstack-bot commented Oct 28, 2020

Hey @Anber, thank you for your pull request 🤗.
The coverage report for this branch can be viewed here.

@Anber Anber mentioned this pull request Oct 28, 2020
Copy link
Member

@satya164 satya164 left a comment

Choose a reason for hiding this comment

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

We also might want to configure paths in our tsconfig.json so that typescript uses the source files when typechecking:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@linaria/*": ["./packages/*/src"]
    },
    "composite": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "esModuleInterop": true,
    "importsNotUsedAsValues": "error",
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": ["esnext", "dom"],
    "module": "esnext",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitUseStrict": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "strict": true,
    "target": "esnext"
  }
}

Though I think we'd need separate build configs for TS in individual packages if we do it:

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "paths": {}
  }
}

docs/CONFIGURATION.md Show resolved Hide resolved
docs/CONFIGURATION.md Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated
@@ -66,80 +65,41 @@
"@types/debug": "^4.1.5",
"@types/dedent": "^0.7.0",
"@types/enhanced-resolve": "^3.0.6",
Copy link
Member

Choose a reason for hiding this comment

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

can we move type dependencies to the relevant packages which need them? e.g. to the webpack loader for enahanced resolve

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lerna suggests keeping dev dependencies on the top level, but it makes sense only if a dependency is used in 2+ packages. However, it has automatically collected deps from all packages :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops. Forgot to clear that mess.

Copy link
Member

Choose a reason for hiding this comment

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

I guess by dev deps it means tooling like esint prettier etc. otherwise it's strange to have a dependency in one place and the type that complements it in a another place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It suggests it mostly because of, in that case, it is easier to maintain deps versions between packages.

Copy link
Member

Choose a reason for hiding this comment

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

imo it's harder to maintain when you have one dependency in a package, and it's corresponding type in another place. when you change version of the package, you also need to remember to change the type to the corresponding version in a totally different place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I definitely agree that @types should be in the same package.json as the dependencies, but what do you think about @babel-packages? They are using in almost all packages and I think it would be better to keep them in the root package.json

packages/babel/tsconfig.json Outdated Show resolved Hide resolved
@Anber
Copy link
Collaborator Author

Anber commented Oct 30, 2020

Hi @satya164!
I hope I got it right :)

{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {}
Copy link
Member

Choose a reason for hiding this comment

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

If a package references other internal package, it's good to set project references as well to provide deterministic builds: https://www.typescriptlang.org/docs/handbook/project-references.html. We use this at Jest monorepo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it really needed if we don't use tsc for building? Lerna itself checks the usages and provides deterministic builds.

Copy link
Member

@satya164 satya164 Oct 30, 2020

Choose a reason for hiding this comment

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

if we don't use tsc for building

we'd still need to use tsc for building type definitions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but it's also called by Lerna in a predefined order.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like https://www.npmjs.com/package/@azu/lerna-to-typescript-project-references can do it automatically. Maybe just add it to prepare step?

package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
@Anber
Copy link
Collaborator Author

Anber commented Oct 30, 2020

I'm ready for the next wave! :)

@Anber
Copy link
Collaborator Author

Anber commented Oct 30, 2020

Oh… well. Something went wrong with references.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

🚀

@Anber Anber merged commit d0430f3 into master Nov 7, 2020
@antitoxic
Copy link

👋 Hey @Anber what the status of that split? I see the webpack docs https://github.com/callstack/linaria/blob/master/docs/BUNDLERS_INTEGRATION.md#webpack refer to A non-existing package called @linaria/webpack-loader.

After some digging in npm I can find @linaria/webpack4-loader, but trying to set this up is blowing up with some babel duplicate plugins errors.

@Anber
Copy link
Collaborator Author

Anber commented Nov 15, 2020

Hi @antitoxic

It's still in the beta. @linaria/webpack-loader is reserved for webpack 4/5 loader and will be released later this month.

trying to set this up is blowing up with some babel duplicate plugins errors.
It should work. Could you please create an issue with details?

@Anber Anber deleted the monorepo branch November 15, 2020 15:27
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.

Migrate Linaria to monorepo under @linaria namespace
5 participants