From 1cc896c8ae9cccac81d05e6b4adf52d55427c9f2 Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Tue, 8 Jun 2021 16:49:06 -0700 Subject: [PATCH] optimize js package folder structure (#7989) * put generated .js files into dist/ folder * format code --- js/common/.gitignore | 6 ------ js/common/.npmignore | 2 +- js/common/package.json | 4 ++-- js/common/tsconfig.json | 2 +- js/node/.gitignore | 4 +--- js/node/.npmignore | 2 +- js/node/package.json | 8 +++---- js/node/script/tsconfig.json | 3 +++ js/node/test/e2e/inference-session-run.ts | 3 +-- js/node/test/e2e/simple-e2e-tests.ts | 3 +-- js/node/test/test-main.ts | 3 +++ js/node/test/test-runner.ts | 3 +-- js/node/test/test-utils.ts | 21 ++++++++++--------- js/node/test/tsconfig.json | 3 +++ .../test/unittests/lib/inference-session.ts | 3 +-- js/node/tsconfig.json | 4 ++-- js/tsconfig.tools.json | 8 +++++++ 17 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 js/node/script/tsconfig.json create mode 100644 js/node/test/tsconfig.json create mode 100644 js/tsconfig.tools.json diff --git a/js/common/.gitignore b/js/common/.gitignore index b40607e089..377e649c45 100644 --- a/js/common/.gitignore +++ b/js/common/.gitignore @@ -1,10 +1,4 @@ node_modules/ -types/ dist/ tsconfig.tsbuildinfo - -lib/**/*.js -lib/**/*.js.map - -*.d.ts diff --git a/js/common/.npmignore b/js/common/.npmignore index 5cac9d846b..a790389cab 100644 --- a/js/common/.npmignore +++ b/js/common/.npmignore @@ -2,6 +2,6 @@ webpack.config.js tsconfig.json -tsconfig.tsbuildinfo +**/*.tsbuildinfo *.tgz diff --git a/js/common/package.json b/js/common/package.json index b918057110..99af180a61 100644 --- a/js/common/package.json +++ b/js/common/package.json @@ -23,8 +23,8 @@ "webpack-cli": "^4.7.0" }, "main": "dist/ort-common.node.js", - "types": "./types/index.d.ts", + "types": "dist/lib/index.d.ts", "jsdelivr": "dist/ort-common.min.js", "unpkg": "dist/ort-common.min.js", - "module": "./lib/index.js" + "module": "dist/lib/index.js" } \ No newline at end of file diff --git a/js/common/tsconfig.json b/js/common/tsconfig.json index 5bb2264203..0683a8a1d7 100644 --- a/js/common/tsconfig.json +++ b/js/common/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "declarationDir": "./types" + "outDir": "dist/lib", }, "include": ["lib"] } diff --git a/js/node/.gitignore b/js/node/.gitignore index 4e76b10f7d..44c390e4bb 100644 --- a/js/node/.gitignore +++ b/js/node/.gitignore @@ -1,12 +1,10 @@ node_modules/ /build/ /bin/ +/dist/ /prebuilds/ /types/ /lib/**/*.js -/lib/**/*.js.map /script/**/*.js -/script/**/*.js.map /test/**/*.js -/test/**/*.js.map diff --git a/js/node/.npmignore b/js/node/.npmignore index f66734bfd4..03940ef2b6 100644 --- a/js/node/.npmignore +++ b/js/node/.npmignore @@ -11,6 +11,6 @@ CMakeLists.txt tsconfig.json -tsconfig.tsbuildinfo +**/*.tsbuildinfo *.tgz diff --git a/js/node/package.json b/js/node/package.json index b65c0cbff6..d0c8991287 100644 --- a/js/node/package.json +++ b/js/node/package.json @@ -21,8 +21,8 @@ "rebuildd": "tsc && node ./script/build --rebuild --config=Debug", "rebuildr": "tsc && node ./script/build --rebuild --config=RelWithDebInfo", "install": "prebuild-install -r napi || (tsc && node ./script/build)", - "prepare": "tsc", - "test": "mocha ./test/test-main", + "prepare": "tsc --build script && tsc", + "test": "tsc --build test && mocha ./test/test-main", "prepack": "node ./script/prepack" }, "dependencies": { @@ -50,8 +50,8 @@ "typedoc": "^0.20.25", "typescript": "^4.2.4" }, - "main": "./lib/index.js", - "types": "./types/lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "os": [ "win32", "darwin", diff --git a/js/node/script/tsconfig.json b/js/node/script/tsconfig.json new file mode 100644 index 0000000000..00f4b1c4b3 --- /dev/null +++ b/js/node/script/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.tools.json" +} diff --git a/js/node/test/e2e/inference-session-run.ts b/js/node/test/e2e/inference-session-run.ts index 65266da950..2ad2272815 100644 --- a/js/node/test/e2e/inference-session-run.ts +++ b/js/node/test/e2e/inference-session-run.ts @@ -1,10 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import {InferenceSession} from 'onnxruntime-common'; +import {InferenceSession, Tensor} from 'onnxruntime-common'; import * as path from 'path'; -import {Tensor} from '../../lib'; import {SQUEEZENET_INPUT0_DATA, SQUEEZENET_OUTPUT0_DATA, TEST_DATA_ROOT} from '../test-utils'; import {assertTensorEqual} from '../test-utils'; diff --git a/js/node/test/e2e/simple-e2e-tests.ts b/js/node/test/e2e/simple-e2e-tests.ts index 091b16a155..dbbcdfcf8d 100644 --- a/js/node/test/e2e/simple-e2e-tests.ts +++ b/js/node/test/e2e/simple-e2e-tests.ts @@ -2,10 +2,9 @@ // Licensed under the MIT License. import assert from 'assert'; -import {InferenceSession} from 'onnxruntime-common'; +import {InferenceSession, Tensor} from 'onnxruntime-common'; import * as path from 'path'; -import {Tensor} from '../../lib'; import {assertDataEqual, TEST_DATA_ROOT} from '../test-utils'; diff --git a/js/node/test/test-main.ts b/js/node/test/test-main.ts index dc12fda0ed..35b5d0006f 100644 --- a/js/node/test/test-main.ts +++ b/js/node/test/test-main.ts @@ -3,6 +3,9 @@ import {NODE_TESTS_ROOT, warmup} from './test-utils'; +// require onnxruntime-node. +require('..'); + // warmup // // for unknown reason, the first call to native InferenceSession::Run() is very slow. diff --git a/js/node/test/test-runner.ts b/js/node/test/test-runner.ts index 853c44b5b9..609f98299e 100644 --- a/js/node/test/test-runner.ts +++ b/js/node/test/test-runner.ts @@ -2,10 +2,9 @@ // Licensed under the MIT License. import * as fs from 'fs-extra'; +import {InferenceSession, Tensor} from 'onnxruntime-common'; import * as path from 'path'; -import {InferenceSession, Tensor} from '../lib'; - import {assertTensorEqual, loadTensorFromFile, shouldSkipModel} from './test-utils'; export function run(testDataFolder: string): void { diff --git a/js/node/test/test-utils.ts b/js/node/test/test-utils.ts index 6b88a00b6a..4613fb7519 100644 --- a/js/node/test/test-utils.ts +++ b/js/node/test/test-utils.ts @@ -5,11 +5,9 @@ import assert from 'assert'; import * as fs from 'fs-extra'; import {jsonc} from 'jsonc'; import * as onnx_proto from 'onnx-proto'; -import {Tensor} from 'onnxruntime-common'; +import {InferenceSession, Tensor} from 'onnxruntime-common'; import * as path from 'path'; -import {binding} from '../lib/binding'; - export const TEST_ROOT = __dirname; export const TEST_DATA_ROOT = path.join(TEST_ROOT, 'testdata'); @@ -72,13 +70,16 @@ export function createTestTensor(type: Tensor.Type, lengthOrDims?: number|number // call the addon directly to make sure DLL is loaded export function warmup(): void { - // we have test cases to verify correctness in other place, so do no check here. - try { - const session = new binding.InferenceSession(); - session.loadModel(path.join(TEST_DATA_ROOT, 'test_types_INT32.pb'), {}); - session.run({input: new Tensor(new Float32Array(5), [1, 5])}, {output: null}, {}); - } catch (e) { - } + describe('Warmup', async function() { + // eslint-disable-next-line no-invalid-this + this.timeout(0); + // we have test cases to verify correctness in other place, so do no check here. + try { + const session = await InferenceSession.create(path.join(TEST_DATA_ROOT, 'test_types_INT32.pb')); + await session.run({input: new Tensor(new Float32Array(5), [1, 5])}, {output: null}, {}); + } catch (e) { + } + }); } export function assertFloatEqual( diff --git a/js/node/test/tsconfig.json b/js/node/test/tsconfig.json new file mode 100644 index 0000000000..00f4b1c4b3 --- /dev/null +++ b/js/node/test/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.tools.json" +} diff --git a/js/node/test/unittests/lib/inference-session.ts b/js/node/test/unittests/lib/inference-session.ts index ba8c2a0ec1..ae23813eb8 100644 --- a/js/node/test/unittests/lib/inference-session.ts +++ b/js/node/test/unittests/lib/inference-session.ts @@ -3,10 +3,9 @@ import assert from 'assert'; import * as fs from 'fs'; -import {InferenceSession} from 'onnxruntime-common'; +import {InferenceSession, Tensor, TypedTensor} from 'onnxruntime-common'; import * as path from 'path'; -import {Tensor, TypedTensor} from '../../../lib'; import {assertTensorEqual} from '../../test-utils'; const SQUEEZENET_INPUT0_DATA = require(path.join(__dirname, '../../testdata/squeezenet.input0.json')); diff --git a/js/node/tsconfig.json b/js/node/tsconfig.json index cb68ecf28e..c8eb433577 100644 --- a/js/node/tsconfig.json +++ b/js/node/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../tsconfig.json", "compilerOptions": { "module": "CommonJS", - "declarationDir": "./types" + "outDir": "dist" }, - "include": ["lib", "script", "test"] + "include": ["lib"] } diff --git a/js/tsconfig.tools.json b/js/tsconfig.tools.json new file mode 100644 index 0000000000..e55ef7e3eb --- /dev/null +++ b/js/tsconfig.tools.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "declaration": false, + "sourceMap": false + } +}