Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Package now consists of ES2015 and commonjs #1576

Merged
merged 9 commits into from
Jan 25, 2018
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change log

### vNext
- Change package to produce ES2015 as `module` and commonjs for `main` [#1576](https://github.com/apollographql/react-apollo/pull/1576)

### 2.1.0-alpha.0

Expand Down
66 changes: 39 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
"module": "src/index.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work, does main and module get added to the package.json that actually gets published?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh, that's no good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait, no, this is ok - it's there for codesandbox. Pay no attention to the /package.json, just to lib/package.json

"scripts": {
"danger": "danger run --verbose",
"deploy":
"./scripts/prepare-package.sh && cd npm && npm publish --tag=alpha",
"predeploy": "npm run compile",
"deploy": "cd lib && npm publish --tag=alpha",
"test": "npm run lint && npm run type-check && npm run jest",
"jest": "jest --maxWorkers=4 --coverage",
"test-watch": "jest --watch",
"test-preact": "jest --config ./jest.preact.config.json --no-cache",
"filesize": "bundlesize",
"type-check": "tsc --project tsconfig.json --noEmit && flow check",
"precompile": "rimraf lib && rimraf npm",
"compile":
"tsc --project tsconfig.json && rimraf lib/test && mv lib/src/* lib/. && rimraf lib/src",
"postcompile":
"rollup -c rollup.config.js && rollup -c rollup.test-utils.config.js",
"precompile": "rimraf lib",
"compile": "npm run compile:esm && npm run compile:cjs",
"compile:esm": "tsc --project tsconfig.json -d && rimraf lib/test && mv lib/src/* lib/. && rimraf lib/src && cd lib && rename js mjs",
"compile:cjs": "tsc --project tsconfig.cjs.json && rimraf lib/test && mv lib/src/* lib/. && rimraf lib/src",
"postcompile": "./scripts/prepare-package.sh",
"watch": "tsc -w",
"lint": "tslint --project tsconfig.json --config tslint.json",
"lint:fix":
"npm run prettier && tslint 'src/*.ts*' --project tsconfig.json --fix",
"lint:fix": "npm run prettier && tslint 'src/*.ts*' --project tsconfig.json --fix",
"lint-staged": "lint-staged",
"prettier":
"prettier --config .prettierrc --write \"{src,test}/**/*.{js,ts}*\""
"prettier": "prettier --write \"{,!(node_modules|lib)/**/}*.{ts*,js*,json,md}\""
},
"bundlesize": [
{
"path": "./lib/umd/react-apollo.js",
"maxSize": "4.81 KB"
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
],
},
"lint-staged": {
"*.{js,ts}*": ["prettier --single-quote --write", "git add"]
"*.{ts*}": [
"prettier --write",
"yarn lint",
"git add"
],
"*.{js*,json,md}": [
"prettier --write",
"git add"
]
},
"pre-commit": "lint-staged",
"repository": {
"type": "git",
"url": "apollostack/react-apollo"
Expand All @@ -51,7 +54,9 @@
],
"author": "James Baxley <[email protected]>",
"babel": {
"presets": ["env"]
"presets": [
"env"
]
},
"jest": {
"testEnvironment": "jsdom",
Expand All @@ -60,15 +65,24 @@
"^.+\\.jsx?$": "babel-jest"
},
"mapCoverage": true,
"moduleFileExtensions": ["ts", "tsx", "js", "json"],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"modulePathIgnorePatterns": [
"<rootDir>/examples",
"<rootDir>/test/flow-usage.js",
"<rootDir>/test/typescript-usage.tsx"
],
"projects": ["<rootDir>"],
"projects": [
"<rootDir>"
],
"testRegex": "(/test/(?!test-utils\b)\b.*|\\.(test|spec))\\.(ts|tsx|js)$",
"setupFiles": ["<rootDir>/test/test-utils/setup.ts"]
"setupFiles": [
"<rootDir>/test/test-utils/setup.ts"
]
},
"license": "MIT",
"peerDependencies": {
Expand All @@ -90,28 +104,26 @@
"babel-core": "6.26.0",
"babel-jest": "22.1.0",
"babel-preset-env": "1.6.1",
"bundlesize": "0.15.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

@rosskevin why are we removing bundlesize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We aren't creating a UMD bundle anymore, not sure if we can size a non-compressed folder of files. I'll check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back to test rollup-produced CJS file

"coveralls": "3.0.0",
"danger": "3.0.5",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1",
"flow-bin": "0.63.1",
"graphql": "0.11.7",
"graphql-tag": "2.6.1",
"husky": "^0.14.3",
"jest": "22.1.1",
"jsdom": "11.5.1",
"lint-staged": "6.0.0",
"pre-commit": "1.2.2",
"preact": "^8.2.7",
"preact-compat": "^3.17.0",
"prettier": "1.10.2",
"react": "16.2.0",
"react-dom": "16.2.0",
"react-test-renderer": "16.2.0",
"recompose": "0.26.0",
"recursive-rename": "^2.0.0",
"rimraf": "2.6.2",
"rollup": "0.54.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not need this anymore? Does typescript handle all of the bundling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tsc does 100% of the transpilation - no more bundles (discussed with @jaydenseric in the thread)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rollup added back for bundlesize only

"rollup-plugin-babel-minify": "3.1.2",
"ts-jest": "22.0.1",
"tslint": "5.9.1",
"typescript": "2.6.2",
Expand Down
21 changes: 0 additions & 21 deletions rollup.config.js

This file was deleted.

21 changes: 0 additions & 21 deletions rollup.test-utils.config.js

This file was deleted.

36 changes: 8 additions & 28 deletions scripts/prepare-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,26 @@
# var language = require('react-apollo/server');
#

# Clear the built output
rm -rf ./lib ./npm

# Compile new files
npm run compile

# Make sure the ./npm directory is empty
rm -rf ./npm
mkdir ./npm

# Copy all files from ./lib to /npm
cd ./lib && cp -r ./ ../npm/

# Back to the root directory
cd ../

# Ensure a vanilla package.json before deploying so other tools do not interpret
# The built output as requiring any further transformation.
node -e "var package = require('./package.json'); \
delete package.babel; \
delete package[\"lint-staged\"]; \
delete package.jest; \
delete package.bundlesize; \
delete package[\"pre-commit\"]; \
delete package[\"husky\"]; \
delete package.scripts; \
delete package.options; \
package.main = 'umd/react-apollo.js'; \
package.module = 'index.js'; \
package['jsnext:main'] = 'index.js'; \
package.main = 'index.js'; \
package.module = 'index.mjs'; \
package.typings = 'index.d.ts'; \
var origVersion = 'local';
var fs = require('fs'); \
fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2)); \
fs.writeFileSync('./lib/package.json', JSON.stringify(package, null, 2)); \
"


# Copy few more files to ./npm
cp README.md npm/
cp LICENSE npm/
cp src/index.js.flow npm/
# please keep this in sync with the filename used in package.main
cp src/index.js.flow npm/umd/react-apollo.js.flow

# Copy few more files to ./lib
cp README.md lib/
cp LICENSE lib/
cp src/index.js.flow lib/
20 changes: 20 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "dom"],
"moduleResolution": "node",
"sourceMap": true,
"noImplicitAny": false,
"outDir": "lib",
"allowSyntheticDefaultImports": false,
"experimentalDecorators": true,
"pretty": true,
"removeComments": true,
"jsx": "react",
"skipLibCheck": true,
"noUnusedLocals": true
},
"include": ["./typings/**/*", "./src/**/*", "./test/**/*"],
"exclude": ["./node_modules", "./dist", "./lib"]
}
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"target": "es2015",
"lib": ["es2015", "dom"],
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"noImplicitAny": false,
"outDir": "lib",
"allowSyntheticDefaultImports": false,
Expand Down
Loading