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

Chore/rollup experiment #152

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f2442b0
chore: added rollup.config.js
eugbyte Aug 2, 2021
aa3fd1a
chore: rename file
eugbyte Aug 2, 2021
d73f392
chore: rollup-experiment
eugbyte Aug 4, 2021
23ddc60
chore: added to package.json
eugbyte Aug 4, 2021
82c1425
chore: refactor
eugbyte Aug 4, 2021
2b9fbf1
chore: refactor
eugbyte Aug 4, 2021
17a614a
chore: remove internal.txt
eugbyte Aug 4, 2021
fdd90ea
chore: remove internal.txt
eugbyte Aug 4, 2021
ad92500
chore: refactor
eugbyte Aug 4, 2021
7d4fe08
chore: exclude oa-verify
eugbyte Aug 17, 2021
f26794d
chore: cleanup
eugbyte Aug 17, 2021
d4eceb4
fix: commitlint
eugbyte Aug 17, 2021
69b6890
chore: remove report.txt
eugbyte Aug 17, 2021
9ec9af7
chore: rename build folder to rollup-build
eugbyte Aug 17, 2021
4d6b009
fix: code review
eugbyte Aug 18, 2021
e23723e
Merge branch 'master' into chore/rollup-experiment
eugbyte Aug 18, 2021
8a09f3b
chore: exclude test files and type files
eugbyte Aug 18, 2021
e0a0adb
chore: restore circleci
eugbyte Aug 18, 2021
9d81914
chore: init eslint config file
eugbyte Aug 18, 2021
f971a41
fix: lint
eugbyte Aug 18, 2021
f332c0e
fix: lint
eugbyte Aug 19, 2021
4dbf39b
chore: remove unused rollup plugins
eugbyte Aug 19, 2021
8e84838
chore: removed unused deps
eugbyte Aug 19, 2021
d81bc03
chore: refactor
eugbyte Aug 19, 2021
919ddaf
fix: lint
eugbyte Aug 19, 2021
de65e56
chore: uninstalled web-streams-polyfill and builtin-modules
eugbyte Aug 19, 2021
f442a8e
chore: update readme on how to run rollup
eugbyte Aug 20, 2021
d147c45
chore: updated readme
eugbyte Aug 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: code review
eugbyte committed Aug 18, 2021
commit 4d6b009cade16a3e2d272a2bc40fb0721589a290
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ jobs:
- run:
name: test
command: npm run test
- run:
name: install ts
command: npm i -g typescript && npm i -g ts-node
- run:
name: benchmark wrap functionality
command: npm run benchmark
61 changes: 40 additions & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -7,39 +7,46 @@ import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import pkge from './package.json'

let filepaths = [];
// Right now, vercel/pkg does not support ESM libraries (https://github.com/vercel/pkg/issues/782)
// For example, some files rely on @govtechsg/open-attestation, @govtechsg/oa-XX. These libraries in turn rely on jsonLd library, which is an ESM library
// To bypass this issue, files that rely on the ESM libraries can be bundled into a single JS file,
// thereby removing the problematic import / export statements.

const walk = (root) => {
// traverse through the directory recursively to get all file paths relative to root directory
const traverseAndGetFilePaths = (root, filepaths = []) => {
let currentPaths = fs.readdirSync(root);
for (let path of currentPaths) {
const abspath = `${root}/${path}`;
const isFile = /.*\.(ts|js|json)$/.test(path);
const absPath = `${root}/${path}`;

const isFile = /.*\.(ts|js|json|file)$/.test(path);
const isDirectory = !isFile;

// exclude type and test files
// const isTestFile = path.includes("test");
// const isTypeFile = path.includes("type");
// const isRegularFile = isFile && !(isTestFile);

if (isFile) {
filepaths.push(abspath);
} else {
// isDirectory
walk(abspath);
filepaths.push(absPath);
} else if (isDirectory) {
traverseAndGetFilePaths(absPath, filepaths);
}
}

return filepaths;
}

walk('./src/commands');
const filepaths = traverseAndGetFilePaths('./src/commands');
filepaths.push("./src/index.ts");

// exclude type and test files
filepaths = filepaths
.filter(path => !path.includes("test"))
.filter(path => !path.includes("type"));
console.log({filepaths});

// console.log(filepaths);
// exclude all external dependencies from being bundled together, except for the problematic jsonLd, used by "@govtechsg/open-attestation", "@govtechsg/oa-XX" dependencies
let deps = [...Object.keys(pkge.dependencies), ...Object.keys(pkge.devDependencies)];
deps = deps
.filter((dep) => !dep.startsWith("@govtechsg/oa-"))
.filter((dep) => !dep.startsWith("@govtechsg/open-attestation"))

// exclude all dependencies from being bundled together, except for the problematic jsonLd, used by "open-attestation", "oa-verify" dependencies
let deps = [...Object.keys(pkge.dependencies), ...Object.keys(pkge.devDependencies)]
deps = deps.filter( (dep) => !(/oa\-|open-attestation/.test(dep)) )

// console.log(deps);
console.log({deps});

export default {
input: filepaths,
@@ -53,11 +60,23 @@ export default {
plugins: [
resolve(),
commonjs(),
typescript(),
typescript({ "module": "esnext" }),
json(),
shebang({
include: './src/index.ts'
}),
multiInput()
],
};

// Explaination of plugins[]
/*
resolve: By default, rollup does not know how to find node modules. For example, for the line, `import axios from "axios" `, rollup thinks that there is a
relative file called axios.js
commonJS: Convert CommonJS modules to ES6, so they can be included in a Rollup bundle. Rollup only recognises es6 js files.
typescript(): Convert typescript to js so that rollup can process. rollup only works on js files by default
json(): Rollup only recognises js file. json() s.json files to ES6 modules
shebang(): to preserver the shebang line #!/usr/bin/env node in src/index.ts
multiInput(): By default Rollup bundles every files into a single file from a single entry point. multiinput() allow us to have multiple entry points and
multiple output paths.
*/
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react",