Skip to content

Commit

Permalink
fix: make it of "module" type
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
swiing committed Apr 30, 2023
1 parent b8084d2 commit 9712c08
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BoolArray from '../src/bitarray';
import { log as _, logHeader as _$ } from './util';
import BoolArray from '../src/bitarray.js';
import { log as _, logHeader as _$ } from './util.js';

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

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@bitarray/es6",
"version": "1.1.2",
"description": "An ES6 BitArray class for easy and native-like operations on sequences of bits",
"type": "module",
"typings": "./dist/esm/src/bitarray.d.ts",
"exports": {
".": {
Expand All @@ -24,13 +25,13 @@
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
"example": "node --loader ts-node/esm example",
"example": "ts-node --esm --project ./tsconfig.esm.json ./example/index.ts",
"postbuild": "bash ./scripts/postbuild.sh",
"prepare": "npm run build",
"prepublishOnly": "npm run test",
"style:fix": "prettier {example,src,test}/**/*.ts --write",
"style:check": "prettier {example,src,test}/**/*.ts --check",
"test": "node --loader ts-node/esm test"
"test": "ts-node --esm --project ./tsconfig.esm.json ./test/index.ts"
},
"author": "swiing",
"license": "MIT",
Expand Down
12 changes: 2 additions & 10 deletions src/bitarray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@

import BitTypedArray from '@bitarray/typedarray';

// missing js extension fails dependent applications
// but adding js extension fails example/test of the library itself
// => quick and dirty solution for now: inline import.
//
// import { base64MIMEChars, base64UrlChars } from './alphabet';
const lettersAndDigits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

const base64MIMEChars = lettersAndDigits + '+/';
const base64UrlChars = lettersAndDigits + '-_';
import { base64MIMEChars, base64UrlChars } from './alphabet.js';

const alphabetLengthErrorMsg = "Alphabet's length must be a power of 2";

// I could leverage _views from @bitarray/typedarray, or create a new one here.
Expand Down
4 changes: 2 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import suite from './suite';
import test from './test';
import suite from './suite.js';
import test from './test.js';

test(suite);
2 changes: 1 addition & 1 deletion test/suite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BitArray from '../src/bitarray';
import BitArray from '../src/bitarray.js';

const len = 42; // choose whatever value

Expand Down

0 comments on commit 9712c08

Please sign in to comment.