Skip to content

Commit

Permalink
fix: correct esm configuration for loadable/server, fixes: #999
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Apr 20, 2024
1 parent c23df05 commit 1d0d111
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 28 deletions.
5 changes: 0 additions & 5 deletions packages/server/.eslintrc.json

This file was deleted.

59 changes: 59 additions & 0 deletions packages/server/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"lib/cjs/index.js": {
"bundled": 18664,
"minified": 10144,
"gzipped": 2837
},
"lib/esm/index.js": {
"bundled": 18299,
"minified": 9859,
"gzipped": 2766,
"treeshaked": {
"rollup": {
"code": 279,
"import_statements": 235
},
"webpack": {
"code": 13218
}
}
},
"dist/loadable-server.cjs.js": {
"bundled": 18664,
"minified": 10144,
"gzipped": 2837
},
"dist/loadable-server.esm.mjs": {
"bundled": 18299,
"minified": 9859,
"gzipped": 2766,
"treeshaked": {
"rollup": {
"code": 279,
"import_statements": 235
},
"webpack": {
"code": 13218
}
}
},
"dist/cjs/loadable-server.cjs.js": {
"bundled": 18664,
"minified": 10144,
"gzipped": 2837
},
"dist/esm/loadable-server.esm.mjs": {
"bundled": 18299,
"minified": 9859,
"gzipped": 2766,
"treeshaked": {
"rollup": {
"code": 279,
"import_statements": 235
},
"webpack": {
"code": 13218
}
}
}
}
19 changes: 8 additions & 11 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"description": "Server utilities for loadable.",
"version": "5.16.2",
"type": "module",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"main": "./dist/cjs/loadable-server.cjs.js",
"module": "./dist/esm/loadable-server.esm.mjs",
"exports": {
".": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"default": "./lib/cjs/index.js"
"require": "./dist/cjs/loadable-server.cjs.js",
"import": "./dist/esm/loadable-server.esm.mjs",
"default": "./dist/cjs/loadable-server.cjs.js"
}
},
"repository": "git@github.com:gregberge/loadable-components.git",
Expand All @@ -29,12 +29,9 @@
},
"license": "MIT",
"scripts": {
"prebuild": "shx rm -rf lib",
"build:esm": "MODULE_TARGET=esm yarn run build:script -d lib/esm",
"build:cjs": "MODULE_TARGET=cjs yarn run build:script -d lib/cjs && yarn run create-cjs-package-json",
"build:script": "BUILD_TARGET=node babel --config-file ../../babel.config.js --ignore \"**/*.test.js\" src",
"build": "yarn build:esm && yarn build:cjs",
"create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json",
"prebuild": "shx rm -rf dist",
"build": "cross-env rollup -c && yarn create-cjs-package-json",
"create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
"prepublishOnly": "yarn run build",
"update-fixtures": "yarn --cwd ../../examples/__fixtures__ build:webpack && rm -rf ./__fixtures__ && cp -R ../../examples/__fixtures__/target ./__fixtures__ "
},
Expand Down
48 changes: 48 additions & 0 deletions packages/server/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable import/no-extraneous-dependencies */
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
import pkg from './package.json'

const input = 'src/index.js'
const name = 'loadable'
const globals = {
react: 'React',
'hoist-non-react-statics': 'hoistNonReactStatics',
}

const external = id => !id.startsWith('.') && !id.startsWith('/')

const getBabelOptions = ({ useESModules }) => ({
exclude: '**/node_modules/**',
runtimeHelpers: true,
presets: [
['@babel/preset-env', { loose: true }],
['@babel/preset-react', { useBuiltIns: true }],
],
plugins: [
'@babel/plugin-proposal-class-properties',
'babel-plugin-annotate-pure-calls',
['@babel/plugin-transform-runtime', { useESModules }],
],
})

export default [
// cjs
{
input,
output: { file: pkg.main, format: 'cjs', exports: 'named' },
external,
plugins: [babel(getBabelOptions({ useESModules: false })), sizeSnapshot()],
},
// esm
{
input,
output: { file: pkg.module, format: 'esm' },
external,
plugins: [babel(getBabelOptions({ useESModules: true })), sizeSnapshot()],
},
]
12 changes: 6 additions & 6 deletions packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable react/no-danger */
import path from 'path'
import fs from 'fs'
import uniq from 'lodash/uniq.js'
import uniqBy from 'lodash/uniqBy.js'
import flatMap from 'lodash/flatMap.js'
import uniq from 'lodash/uniq'
import uniqBy from 'lodash/uniqBy'
import flatMap from 'lodash/flatMap'
import React from 'react'
import { invariant, getRequiredChunkKey } from './sharedInternals.js'
import ChunkExtractorManager from './ChunkExtractorManager.js'
import { smartRequire, joinURLPath, readJsonFileSync } from './util.js'
import { invariant, getRequiredChunkKey } from './sharedInternals'
import ChunkExtractorManager from './ChunkExtractorManager'
import { smartRequire, joinURLPath, readJsonFileSync } from './util'

const EXTENSION_SCRIPT_TYPES = {
'.js': 'script',
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/ChunkExtractor.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
import 'regenerator-runtime/runtime.js'
import 'regenerator-runtime/runtime'
import path from 'path'
import stats from '../__fixtures__/stats.json'
import ChunkExtractor from './ChunkExtractor.js'
import ChunkExtractor from './ChunkExtractor'

const targetPath = path.resolve(
__dirname,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/ChunkExtractorManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Context } from './sharedInternals.js'
import { Context } from './sharedInternals'

const ChunkExtractorManager = ({ extractor, children }) => (
<Context.Provider value={extractor}>{children}</Context.Provider>
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as ChunkExtractorManager } from './ChunkExtractorManager.js'
export { default as ChunkExtractor } from './ChunkExtractor.js'
export { default as ChunkExtractorManager } from './ChunkExtractorManager'
export { default as ChunkExtractor } from './ChunkExtractor'
2 changes: 1 addition & 1 deletion packages/server/src/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { joinURLPath } from './util.js'
import { joinURLPath } from './util'

describe('util', () => {
describe('#joinURLPath', () => {
Expand Down
76 changes: 76 additions & 0 deletions packages/server/yarn-error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Arguments:
/Users/akorzunov/.nvm/versions/node/v16.20.2/bin/node /opt/homebrew/Cellar/yarn/1.22.19/libexec/bin/yarn.js run prepublishOnly

PATH:
/Users/akorzunov/.nvm/versions/node/v16.20.2/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/opt/atlassian/bin

Yarn version:
1.22.19

Node version:
16.20.2

Platform:
darwin arm64

Trace:
SyntaxError: /Users/akorzunov/dev/github/loaders/loadable-components/packages/server/package.json: Unexpected token } in JSON at position 1190
at JSON.parse (<anonymous>)
at /opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:1629:59
at Generator.next (<anonymous>)
at step (/opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:310:30)
at /opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:321:13

npm manifest:
{
"name": "@loadable/server",
"description": "Server utilities for loadable.",
"version": "5.16.2",
"type": "module",
"main": "./dist/cjs/loadable-server.cjs.js",
"module": "./dist/esm/loadable-server.esm.mjs",
"exports": {
".": {
"require": "./dist/cjs/loadable-server.cjs.js",
"import": "./dist/esm/loadable-server.esm.mjs",
"default": "./dist/cjs/loadable-server.cjs.js"
}
},
"repository": "git@github.com:gregberge/loadable-components.git",
"author": "Greg Bergé <berge.greg@gmail.com>",
"publishConfig": {
"access": "public"
},
"keywords": [
"loadable"
],
"engines": {
"node": ">=8"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/gregberge"
},
"license": "MIT",
"scripts": {
"prebuild": "shx rm -rf dist",
"build": "cross-env rollup -c && yarn create-cjs-package-json",
"create-cjs-package-json": "echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json",
"prepublishOnly": "yarn run build",
"update-fixtures": "yarn --cwd ../../examples/__fixtures__ build:webpack && rm -rf ./__fixtures__ && cp -R ../../examples/__fixtures__/target ./__fixtures__ ",

},
"peerDependencies": {
"@loadable/component": "^5.0.1",
"react": "^16.3.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"lodash": "^4.17.15"
}
}

yarn manifest:
No manifest

Lockfile:
No lockfile

0 comments on commit 1d0d111

Please sign in to comment.