Skip to content

Commit

Permalink
ES Module
Browse files Browse the repository at this point in the history
  • Loading branch information
kawanet committed Dec 14, 2024
1 parent 26a843e commit a7a070c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
*.min.js.gz
*.mjs
*.tgz
*~
.DS_Store
.idea
.idea/
.vscode/
.nyc_output/
gh-pages
node_modules
npm-debug.log*
package-lock.json
~$*
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/usr/bin/env bash -c make

SRC=./int64-buffer.js
TESTS=./test/*.js
JSTEST=./test/test.js
DIST=./dist
JSDEST=./dist/int64-buffer.min.js
JSGZIP=./dist/int64-buffer.min.js.gz
ESMDEST=./int64-buffer.mjs
ESMTEST=./test/test.mjs

all: $(JSGZIP)
all: $(JSGZIP) $(ESMDEST)

clean:
rm -fr $(JSDEST) $(JSGZIP)
rm -fr $(JSDEST) $(JSGZIP) $(ESMDEST) $(ESMTEST)

$(DIST):
mkdir -p $@
Expand All @@ -27,10 +29,23 @@ test-coverage:
./node_modules/.bin/nyc make mocha
./node_modules/.bin/nyc report --reporter=text-lcov > .nyc_output/lcov.info

mocha:
./node_modules/.bin/mocha -R spec $(TESTS)
mocha: $(JSTEST) $(ESMTEST)
./node_modules/.bin/mocha -R spec $(JSTEST)
./node_modules/.bin/mocha -R spec $(ESMTEST)

jshint:
./node_modules/.bin/jshint .

.PHONY: all clean test jshint mocha
#### ES Module

$(ESMDEST): $(SRC) Makefile
mkdir -p $(dir $@)
perl -pe 's#^(var|.*export)#/// $$1#; s#^(\s*)(\S.*= )(factory.")#$$1export const $$2/* \@__PURE__ */ $$3#' < $< > $@

$(ESMTEST): $(JSTEST) Makefile
mkdir -p $(dir $@)
perl -pe 's#^(var exported)#/// $$1#; s#^.*#import * as exported from "../int64-buffer.mjs";# if $$. == 1' < $< > $@

####

.PHONY: all clean test jshint mocha esm
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
"nyc": "^17.1.0",
"terser": "^5.37.0"
},
"exports": {
"types": "./int64-buffer.d.ts",
"import": "./int64-buffer.mjs",
"require": "./int64-buffer.js"
},
"files": [
"LICENSE",
"README.md",
"dist/int64-buffer.min.js",
"int64-buffer.js",
"int64-buffer.d.ts"
"int64-buffer.d.ts",
"int64-buffer.mjs"
],
"homepage": "https://github.com/kawanet/int64-buffer",
"jshintConfig": {
Expand Down Expand Up @@ -65,5 +71,6 @@
"prepack": "make clean all test",
"test": "make test"
},
"type": "commonjs",
"typings": "int64-buffer.d.ts"
}

0 comments on commit a7a070c

Please sign in to comment.