Skip to content

Commit

Permalink
[build]: Replace node_modules with a single-file bundle produced by…
Browse files Browse the repository at this point in the history
… `ncc`

Detailed description of changes:

* Add `package` script to `package.json` that builds the TypeScript code
  and "links" it together with all of its (transitive) dependencies in a
  single `index.js` file.

* Change the `main` file in `package.json` to `dist/index.js`.
  `ncc` allows only the out dir can be specified - the filename is
  always `index.js`.

* Add `lib/` and `dist/*` to .gitingore, but exclude `dist/index.js` so
  it will be committed.

* Delete the `node_modules` and `lib` folders

* Add a `.gitattributes` file in order to set mark `dist/index.js` as
  `binary` for git diff and merge purposes

* Update `.gitignore` to the latest version from `https://github.com/github/gitignore/blob/master/Node.gitignore`

* Set the `target` in `tsconfig.json` to `es2017`, which is [supported by
  current Node.js version - v12][1], as should make for cleaner generated
  "down-leveled" code as it has native async/await support

[1]: https://node.green/
  • Loading branch information
PetarKirov committed Feb 9, 2021
1 parent 40bd052 commit fc426c1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mark .pnp.cjs as binary to prevent git from trying to merge it
/dist/index.js binary linguist-generated
/.pnp.* binary linguist-generated
/.yarn/releases/** binary linguist-generated

# Set the language for these files to json5 to ensure GitHub doesn't show the comments as errors
/.vscode/*.json linguist-language=JSON5
tsconfig.json linguist-language=JSON5
39 changes: 35 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__tests__/runner/*
lib/
dist/*
!dist/index.js

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
Expand Down Expand Up @@ -41,10 +44,11 @@ bower_components
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo
Expand All @@ -55,6 +59,12 @@ typings/
# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -70,13 +80,21 @@ typings/

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# next.js build output
# Next.js build output
.next
out

# nuxt.js build output
# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

Expand All @@ -88,3 +106,16 @@ typings/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "1.0.6",
"private": false,
"description": "Installation of the requested D compiler",
"main": "lib/main.js",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"package": "ncc build --source-map --license licenses.txt"
"package": "ncc build src/main.ts -o dist --minify --target es2017"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
Expand Down

0 comments on commit fc426c1

Please sign in to comment.