Skip to content

Commit

Permalink
feat: migrate to native esm (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Aug 7, 2021
1 parent fe6af2c commit 106aaf6
Show file tree
Hide file tree
Showing 31 changed files with 20,680 additions and 4,284 deletions.
9 changes: 9 additions & 0 deletions .changeset/shaggy-chairs-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@pkgr/es-modules": minor
"@pkgr/imagemin": minor
"@pkgr/rollup": minor
"@pkgr/umd-globals": minor
"@pkgr/utils": minor
---

feat: migrate to native esm
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# `@pkgr/utils` is used by `@1stg/lint-staged`
- name: Build prerelease
run: yarn run-s build:ts build:r
run: yarn build:lib

- name: Create Release Pull Request or Publish to npm
id: changesets
Expand Down
93 changes: 47 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"packages/*"
],
"scripts": {
"build": "run-s build:ts build:r build:w",
"build:r": "ts-node --files packages/rollup/src/cli -d false --exclude webpack-*",
"build": "run-s build:lib build:w",
"build:lib": "run-s build:ts build:r",
"build:r": "node --loader ts-node/esm packages/rollup/src/cli.ts -f cjs -d false --exclude webpack-*",
"build:ts": "tsc -b",
"build:w": "rimraf dist && run-p build:w:*",
"build:w:angular": "yarn w:build -e src/angular -o dist/angular -t angular -p",
Expand All @@ -30,25 +31,26 @@
"lint:style": "stylelint --cache './**/*.{html,js,scss,ts,vue}'",
"lint:ts": "tslint -p . -t stylish",
"lint:tsc": "tsc --noEmit",
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer && t || exit 0",
"prelint": "yarn build:lib",
"prepare": "simple-git-hooks && yarn-deduplicate --strategy fewer && t || exit 0",
"pretest": "yarn clean",
"release": "changeset publish",
"serve": "serve dist",
"test": "jest",
"typecov": "type-coverage",
"w:build": "ts-node --files packages/webpack/src/cli",
"w:dev": "ts-node -T --files packages/webpack/src/cli"
"w:build": "ts-node packages/webpack/src/cli",
"w:dev": "ts-node packages/webpack/src/cli"
},
"devDependencies": {
"@1stg/app-config": "^2.2.0",
"@1stg/app-config": "^2.2.1",
"@1stg/tslint-config": "^2.0.0",
"@angular/common": "^12.0.3",
"@angular/compiler": "^12.0.3",
"@angular/compiler-cli": "^12.0.3",
"@angular/core": "^12.0.3",
"@angular/platform-browser": "^12.0.3",
"@angular/platform-browser-dynamic": "^12.0.3",
"@babel/types": "^7.14.4",
"@angular/common": "^12.2.0",
"@angular/compiler": "^12.2.0",
"@angular/compiler-cli": "^12.2.0",
"@angular/core": "^12.2.0",
"@angular/platform-browser": "^12.2.0",
"@angular/platform-browser-dynamic": "^12.2.0",
"@babel/types": "^7.15.0",
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@d-ts/bin": "^1.0.0",
Expand All @@ -57,48 +59,47 @@
"@d-ts/svelte": "^1.0.0",
"@d-ts/vue": "^1.0.0",
"@d-ts/webpack-plugins": "^1.0.0",
"@types/babel__core": "^7.1.14",
"@types/case-sensitive-paths-webpack-plugin": "^2.1.5",
"@types/copy-webpack-plugin": "^8.0.0",
"@types/babel__core": "^7.1.15",
"@types/case-sensitive-paths-webpack-plugin": "^2.1.6",
"@types/copy-webpack-plugin": "^8.0.1",
"@types/cross-spawn": "^6.0.2",
"@types/debug": "^4.1.5",
"@types/friendly-errors-webpack-plugin": "^0.1.3",
"@types/imagemin": "^7.0.0",
"@types/is-glob": "^4.0.1",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.170",
"@types/micromatch": "^4.0.1",
"@types/mini-css-extract-plugin": "^1.4.3",
"@types/node": "^15.12.0",
"@types/debug": "^4.1.7",
"@types/friendly-errors-webpack-plugin": "^0.1.4",
"@types/imagemin": "^7.0.1",
"@types/is-glob": "^4.0.2",
"@types/jest": "^26.0.24",
"@types/lodash-es": "^4.14.172",
"@types/micromatch": "^4.0.2",
"@types/mini-css-extract-plugin": "^2.0.1",
"@types/node": "^16.4.13",
"@types/postcss-load-config": "^3.0.1",
"@types/prettier": "^2.2.3",
"@types/react": "^17.0.9",
"@types/react-dom": "^17.0.6",
"@types/resolve": "^1.20.0",
"@types/webpack-dev-server": "^3.11.4",
"@types/webpack-env": "^1.16.0",
"@types/workbox-webpack-plugin": "^5.1.6",
"core-js": "^3.13.1",
"jest": "^27.0.4",
"postcss": "^8.3.0",
"@types/prettier": "^2.3.2",
"@types/react": "^17.0.16",
"@types/react-dom": "^17.0.9",
"@types/resolve": "^1.20.1",
"@types/webpack-dev-server": "^3.11.5",
"@types/webpack-env": "^1.16.2",
"@types/workbox-webpack-plugin": "^5.1.8",
"@vue/compiler-sfc": "^3.1.5",
"core-js": "^3.16.0",
"jest": "^27.0.6",
"postcss": "^8.3.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.1.0",
"serve": "^11.3.2",
"svelte": "^3.38.2",
"ts-jest": "^27.0.2",
"ts-node": "^10.0.0",
"rxjs": "^7.3.0",
"serve": "^12.0.0",
"svelte": "^3.42.1",
"ts-jest": "^27.0.4",
"ts-node": "^10.1.0",
"tslint": "^6.1.3",
"type-coverage": "^2.17.5",
"typescript": "^4.3.2",
"vue": "^2.6.13",
"vue-template-compiler": "^2.6.13",
"type-coverage": "^2.18.0",
"typescript": "^4.3.5",
"vue": "^3.1.5",
"zone.js": "^0.11.4"
},
"resolutions": {
"prettier": "^2.3.0"
"prettier": "^2.3.2"
},
"commitlint": {
"extends": [
Expand Down
11 changes: 5 additions & 6 deletions packages/es-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"name": "@pkgr/es-modules",
"version": "0.4.2",
"type": "module",
"description": "Union collections of es modules mappings for pkgs without or with incorrect `module` field",
"repository": "git+https://github.com/rx-ts/pkgr.git",
"homepage": "https://github.com/rx-ts/pkgr/blob/master/packages/es-modules",
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"main": "lib/cjs",
"module": "lib",
"es2015": "lib/es2015",
"fesm5": "lib/esm",
"jsdelivr": "lib/umd",
"unpkg": "lib/umd",
"exports": {
"import": "./lib/index.js",
"require":"./lib/index.cjs"
},
"types": "lib",
"files": [
"lib",
Expand Down
13 changes: 7 additions & 6 deletions packages/imagemin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@pkgr/imagemin",
"version": "1.0.1",
"type": "module",
"description": "Seamless imagemin API wrapper to minify images, working perfectly with lint-staged also",
"repository": "git@github.com:rx-ts/pkgr.git",
"homepage": "https://github.com/rx-ts/pkgr/blob/master/packages/imagemin",
Expand All @@ -12,10 +13,10 @@
"bin": {
"i": "lib/cli.js"
},
"main": "lib/cjs",
"module": "lib",
"es2015": "lib/es2015",
"fesm5": "lib/esm",
"exports": {
"import": "./lib/index.js",
"require":"./lib/index.cjs"
},
"types": "lib",
"files": [
"lib"
Expand All @@ -28,11 +29,11 @@
"imagemin-optipng": "^8.0.0",
"imagemin-pngquant": "^9.0.2",
"imagemin-svgo": "^9.0.0",
"imagemin-upng": "^2.0.2",
"imagemin-upng": "^3.0.0",
"imagemin-webp": "^6.0.0",
"is-glob": "^4.0.1",
"tiny-glob": "^0.2.9",
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
24 changes: 16 additions & 8 deletions packages/imagemin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs'

import { Plugin } from 'imagemin'

const plugins = (
[
[
Expand Down Expand Up @@ -50,13 +52,19 @@ const plugins = (
},
],
] as const
).map(
([name, opts]) =>
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires
require(`imagemin-${name}`)(opts) as import('imagemin').Plugin,
).map(async ([name, opts]) =>
(
(await import(`imagemin-${name}`)) as {
default: (opts: unknown) => Plugin
}
).default(opts),
)

export default (filename: string) =>
plugins
.reduce((acc, it) => acc.then(it), fs.promises.readFile(filename))
.then(it => fs.promises.writeFile(filename, it))
export default async (filename: string) =>
fs.promises.writeFile(
filename,
await plugins.reduce(
async (acc, it) => (await it)(await acc),
fs.promises.readFile(filename),
),
)
33 changes: 17 additions & 16 deletions packages/rollup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@pkgr/rollup",
"version": "1.1.4",
"type": "module",
"description": "Seamless Rollup bundler wrapper for libraries",
"repository": "git@github.com:rx-ts/pkgr.git",
"homepage": "https://github.com/rx-ts/pkgr/blob/master/packages/rollup",
Expand All @@ -16,37 +17,37 @@
"lib"
],
"dependencies": {
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-decorators": "^7.14.2",
"@babel/preset-env": "^7.14.4",
"@babel/preset-typescript": "^7.13.0",
"@babel/core": "^7.15.0",
"@babel/plugin-proposal-decorators": "^7.14.5",
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@pkgr/es-modules": "^0.4.0",
"@pkgr/umd-globals": "^0.6.0",
"@pkgr/utils": "^1.0.0",
"@rollup/plugin-babel": "^5.2.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-url": "^6.0.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-url": "^6.1.0",
"@rxts/rollup-plugin-alias": "^0.1.1",
"builtin-modules": "^3.1.0",
"commander": "^7.2.0",
"core-js": "^3.13.1",
"debug": "^4.1.1",
"esbuild": "^0.12.6",
"commander": "^8.1.0",
"core-js": "^3.16.0",
"debug": "^4.3.2",
"esbuild": "^0.12.18",
"is-glob": "^4.0.1",
"jsox": "^1.1.121",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"micromatch": "^4.0.4",
"rollup": "^2.50.6",
"rollup": "^2.56.0",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-esbuild": "^4.5.0",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-vue": "^6.0.0",
"rollup-plugin-vue-jsx-compat": "^0.0.2",
"tslib": "^2.2.0"
"rollup-plugin-vue-jsx-compat": "^0.0.6",
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
21 changes: 15 additions & 6 deletions packages/rollup/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/unbound-method */
import { tryRequirePkg } from '@pkgr/utils'
import program from 'commander'
import { program } from 'commander'
import debug from 'debug'
import JSOX from 'jsox'
import pick from 'lodash/pick'
// @ts-expect-error
import { JSOX } from 'jsox'
import { pick } from 'lodash-es'
import { InputOptions, OutputOptions, rollup, watch } from 'rollup'

import config, { ConfigOptions } from './config'
import config, { ConfigOptions } from './config.js'

const info = debug('r:info')

Expand All @@ -29,6 +29,7 @@ program
.option(
'-m, --monorepo <false | glob | paths>',
'whether try to resolve the project as a monorepo automatically, or custom the packages path',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
Expand All @@ -44,16 +45,19 @@ program
.option(
'-g, --globals <JSOX>',
'JSON string to be parsed as umd globals map',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
'-a, --alias-entries <JSOX>',
'entries setting for @rxts/rollup-plugin-alias, could be array or object',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
'-c, --copies <JSOX>',
'targets setting or whole CopyOptions for rollup-plugin-copy, could be array or object',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
Expand All @@ -68,27 +72,32 @@ program
.option(
'-b, --babel <JSOX>',
'Overrides the Babel plugin options for `@rollup/plugin-babel`',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
'--esbuild <JSOX>',
'Overrides the esbuild options for `rollup-plugin-esbuild`',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
)
.option(
'-t, --transformer [babel | esbuild]',
'Specify which transformer to use',
'esbuild',
)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.option('--postcss <JSOX>', 'options for `rollup-plugin-postcss`', JSOX.parse)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.option('--vue <JSOX>', 'options for `rollup-plugin-vue`', JSOX.parse)
.option<boolean | object>(
'-d, --define [boolean | JSOX]',
'options for `@rollup/plugin-replace`, enable `__DEV__` and `__PROD__` by default',
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
JSOX.parse,
true,
)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.option('--terser <JSOX>', 'options for `@rollup/plugin-terser`', JSOX.parse)
.option(
'-p, --prod [boolean]',
Expand Down
Loading

0 comments on commit 106aaf6

Please sign in to comment.