Skip to content

Commit

Permalink
[v2.0.0] Avoid empty imports from side-effect-free chunks (#3369)
Browse files Browse the repository at this point in the history
* Respect moduleSideEffects when inlining empty imports

* Make dependencies a Set

* Also handle side-effect free reexports correctly without generating separate chunks

* Infer side-effect free modules and hoist side-effects

* Simplify some logic

* Better encapsulate chunk assignment

* Get rid of colouring hashes

* Improve coverage

* Store the build output as artifact and post an automated comment
  • Loading branch information
lukastaegert committed Feb 8, 2020
1 parent 15a4cd4 commit 467d666
Show file tree
Hide file tree
Showing 202 changed files with 1,203 additions and 547 deletions.
33 changes: 19 additions & 14 deletions .circleci/config.yml
@@ -1,14 +1,5 @@
version: 2

unit_tests: &unit_tests
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Run unit tests.
command: npm run ci:test

jobs:
analysis:
docker:
Expand All @@ -18,13 +9,13 @@ jobs:
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
name: Installing Dependencies
command: npm ci --ignore-scripts
- run:
name: Run linting.
name: Running linting
command: npm run ci:lint
- run:
name: Run NPM Security Audit
name: Running NPM Security Audit
command: npm run security
- save_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
Expand All @@ -33,7 +24,20 @@ jobs:
node-v10-latest:
docker:
- image: rollupcabal/circleci-node-v10:latest
<<: *unit_tests
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Running tests
command: npm run ci:test
- store_artifacts:
name: Storing browser build for REPL
path: /home/circleci/project/dist/rollup.browser.js
destination: rollup.browser.js
- run:
name: Post REPL comment
command: ./scripts/post-comment.js
node-v12-latest:
docker:
- image: rollupcabal/circleci-node-v12:latest
Expand All @@ -42,9 +46,10 @@ jobs:
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Run tests with coverage.
name: Running tests with coverage
command: npm run ci:coverage


workflows:
version: 2
validate-test:
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -32,7 +32,7 @@
"plugin:import/warnings"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -97,6 +97,7 @@
"micromatch": "^4.0.2",
"minimist": "^1.2.0",
"mocha": "^6.2.2",
"node-fetch": "^2.6.0",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"pretty-bytes": "^5.3.0",
Expand Down
60 changes: 60 additions & 0 deletions scripts/post-comment.js
@@ -0,0 +1,60 @@
#!/usr/bin/env node

const path = require('path');
const fetch = require('node-fetch');

const authToken = process.env.GH_AUTH_TOKEN;
if (!authToken) {
throw new Error('Could not find auth token.');
}

const prNumber = path.basename(
process.env.CIRCLE_PULL_REQUEST || process.env.CI_PULL_REQUEST || ''
);
if (!prNumber) {
console.log('No pull request number found');
process.exit(0);
}

const headline = '### Thank you for your contribution! ❤️';

postComment();

async function postComment() {
const existingId = await findExistingComment();
console.log(existingId ? `Update comment ${existingId}` : 'Create new comment.');
const installPath = await getInstallPath();
const path = existingId ? `issues/comments/${existingId}` : `issues/${prNumber}/comments`;
const method = existingId ? 'PATCH' : 'POST';
await fetch(getApiUrl(path), {
method,
body: JSON.stringify({
body: `${headline}
You can try out this pull request locally via
\`\`\`
npm install ${installPath}
\`\`\`
or load it into the REPL:
https://rollupjs.org/repl/?circleci=${process.env.CIRCLE_BUILD_NUM}
`
})
});
}

async function findExistingComment() {
const comments = await (await fetch(getApiUrl(`issues/${prNumber}/comments`), {})).json();
const existingComment = comments.find(comment => comment.body.startsWith(headline));
return existingComment && existingComment.id;
}

async function getInstallPath() {
const prInfo = await (await fetch(getApiUrl(`pulls/${prNumber}`), {})).json();
return `${prInfo.head.repo.full_name}#${prInfo.head.ref}`;
}

function getApiUrl(path) {
return `https://${authToken}:x-oauth-basic@api.github.com/repos/rollup/rollup/${path}`;
}

0 comments on commit 467d666

Please sign in to comment.