Skip to content

Commit 9712c08

Browse files
committed
fix: make it of "module" type
When running tests, node 20 complains: " SyntaxError: Cannot use import statement outside a module " (interestingly enough, previous versions of node do not complain) Even prior to using node v20, there has been confusion, as seen from e.g. b380b88 (Note on why this is related: modules _do_ require use of file extensions in import statements) Hopefully this change makes it clean for all (node, ts-node and dependents importing this package)
1 parent b8084d2 commit 9712c08

File tree

5 files changed

+10
-17
lines changed

5 files changed

+10
-17
lines changed

example/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import BoolArray from '../src/bitarray';
2-
import { log as _, logHeader as _$ } from './util';
1+
import BoolArray from '../src/bitarray.js';
2+
import { log as _, logHeader as _$ } from './util.js';
33

44
import { bit } from '@bitarray/typedarray';
55

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@bitarray/es6",
33
"version": "1.1.2",
44
"description": "An ES6 BitArray class for easy and native-like operations on sequences of bits",
5+
"type": "module",
56
"typings": "./dist/esm/src/bitarray.d.ts",
67
"exports": {
78
".": {
@@ -24,13 +25,13 @@
2425
"build:cjs": "tsc -p tsconfig.cjs.json",
2526
"build:esm": "tsc -p tsconfig.esm.json",
2627
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
27-
"example": "node --loader ts-node/esm example",
28+
"example": "ts-node --esm --project ./tsconfig.esm.json ./example/index.ts",
2829
"postbuild": "bash ./scripts/postbuild.sh",
2930
"prepare": "npm run build",
3031
"prepublishOnly": "npm run test",
3132
"style:fix": "prettier {example,src,test}/**/*.ts --write",
3233
"style:check": "prettier {example,src,test}/**/*.ts --check",
33-
"test": "node --loader ts-node/esm test"
34+
"test": "ts-node --esm --project ./tsconfig.esm.json ./test/index.ts"
3435
},
3536
"author": "swiing",
3637
"license": "MIT",

src/bitarray.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,8 @@
2525

2626
import BitTypedArray from '@bitarray/typedarray';
2727

28-
// missing js extension fails dependent applications
29-
// but adding js extension fails example/test of the library itself
30-
// => quick and dirty solution for now: inline import.
31-
//
32-
// import { base64MIMEChars, base64UrlChars } from './alphabet';
33-
const lettersAndDigits =
34-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
35-
36-
const base64MIMEChars = lettersAndDigits + '+/';
37-
const base64UrlChars = lettersAndDigits + '-_';
28+
import { base64MIMEChars, base64UrlChars } from './alphabet.js';
29+
3830
const alphabetLengthErrorMsg = "Alphabet's length must be a power of 2";
3931

4032
// I could leverage _views from @bitarray/typedarray, or create a new one here.

test/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import suite from './suite';
2-
import test from './test';
1+
import suite from './suite.js';
2+
import test from './test.js';
33

44
test(suite);

test/suite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import BitArray from '../src/bitarray';
1+
import BitArray from '../src/bitarray.js';
22

33
const len = 42; // choose whatever value
44

0 commit comments

Comments
 (0)