diff --git a/package.json b/package.json index dd0a7b8..6c5a73d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.1.3", "license": "MIT", "main": "./lib-node/index_node.js", + "types": "./types/index_node.d.ts", "module": "./lib/index.js", "browser": "./lib/index.js", "exports": { @@ -15,8 +16,9 @@ "clean-modules": "rm -rf lib", "build:node": "tsc -p tsconfig.cjs.json", "build:web": "tsc -p tsconfig.esm.json", - "build": "npm run clean-modules && npm run build:node && npm run build:web", - "test": "node_modules/.bin/ava" + "build": "npm run clean-modules && npm run build:node && npm run build:web && npm run generate-types", + "test": "node_modules/.bin/ava", + "generate-types": "tsc src/*.ts --declaration --emitDeclarationOnly --outDir types" }, "devDependencies": { "@types/node": "^18.11.17", @@ -27,6 +29,7 @@ "lib", "lib-node", "src", + "types", "package.json" ] } diff --git a/test/cjs_initialization.test.cjs b/test/cjs_initialization.test.cjs index bd56616..d83f5b1 100644 --- a/test/cjs_initialization.test.cjs +++ b/test/cjs_initialization.test.cjs @@ -1,6 +1,6 @@ const test = require('ava'); -const { initialiseResolver, read_file } = require("../lib/index_node.js"); +const { initialiseResolver, read_file } = require("../lib-node/index_node.js"); test('It reads file from file system within read_file using default implementation.', t => { @@ -48,4 +48,4 @@ test('It communicates error when resolver is initialized to anything but a funct t.is(error.message, 'Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter'); -}); \ No newline at end of file +}); diff --git a/test/esm_initialization.test.mjs b/test/esm_initialization.test.mjs index 4ba0af3..30f77dc 100644 --- a/test/esm_initialization.test.mjs +++ b/test/esm_initialization.test.mjs @@ -1,11 +1,11 @@ /** - * Below tests are commented because they require + * Below tests are commented because they require * "type": "module", in package.json * Seems that both CJS and MJS modes are not going to work. */ import test from 'ava'; -import { initialiseResolver, read_file } from "../lib/index.js"; +import { initialiseResolver, read_file } from "../lib-node/index.js"; test('It communicates error when read_file was called before initialiseResolver.', t => { @@ -55,4 +55,4 @@ test('It communicates error when resolver is initialized to anything but a funct t.is(error.message, 'Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter'); -}); \ No newline at end of file +}); diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..14f4c17 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,2 @@ +export declare let read_file: (source_id: any) => string; +export declare function initialiseResolver(resolver: (source_id: String) => string): void; diff --git a/types/index_node.d.ts b/types/index_node.d.ts new file mode 100644 index 0000000..75e87c0 --- /dev/null +++ b/types/index_node.d.ts @@ -0,0 +1,2 @@ +import { initialiseResolver, read_file } from './index.js'; +export { initialiseResolver, read_file };