From aa324c49ae3ae33b80b05ecb71315bc78799f2c1 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:13:15 -0400 Subject: [PATCH 01/27] Deprecate scaffolding for default model - Also deprecate leveraging build-model script in favor of package.json scripts --- .deepsource.toml | 1 - .../src/lib/package-scripts/build-model.ts | 4 +- models/default-model/package.json | 19 ++-- models/default-model/src/index.ts | 6 +- models/default-model/tsconfig.cjs.json | 4 - models/rollup.config.cjs | 20 ++++ models/tsconfig.cjs.json | 6 +- models/tsconfig.json | 2 + pnpm-lock.yaml | 99 +++++++++++++++---- .../package-scripts/scaffold-dependencies.ts | 26 +---- 10 files changed, 122 insertions(+), 65 deletions(-) create mode 100644 models/rollup.config.cjs diff --git a/.deepsource.toml b/.deepsource.toml index 21487ffb9..76c49f189 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -10,7 +10,6 @@ exclude_patterns = [ "examples/**", "scripts/**", "test/**", - "packages/test-scaffolding/**", "dev/**", ] diff --git a/internals/upscaler-cli/src/lib/package-scripts/build-model.ts b/internals/upscaler-cli/src/lib/package-scripts/build-model.ts index 95ed0902d..8d2ca2a54 100644 --- a/internals/upscaler-cli/src/lib/package-scripts/build-model.ts +++ b/internals/upscaler-cli/src/lib/package-scripts/build-model.ts @@ -221,7 +221,9 @@ const buildModel = async ( if (opts.verbose) { console.log(`Scaffolding dependencies for model ${model}`); } - scaffoldDependencies(MODEL_ROOT, scaffoldDependenciesConfig); + if (model !== 'default-model') { + scaffoldDependencies(MODEL_ROOT, scaffoldDependenciesConfig); + } // rimraf(DIST); // await mkDistFolder(DIST); diff --git a/models/default-model/package.json b/models/default-model/package.json index a6491a468..c45a67c8d 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -24,16 +24,17 @@ } }, "scripts": { - "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/default-model --config models/scaffolder.ts", "lint:fix": "pnpm lint --fix", - "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "lint": "eslint -c ../.eslintrc.js src --ext .ts", "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model", "build": "ts-node ../../scripts/package-scripts/build-model.ts default-model -o cjs -o esm -o umd --skipCheckModelsExist", - "build:cjs": "ts-node ../../scripts/package-scripts/build-model.ts default-model -o cjs", - "build:esm": "ts-node ../../scripts/package-scripts/build-model.ts default-model -o esm", - "build:umd": "ts-node ../../scripts/package-scripts/build-model.ts default-model -o umd", - "clean": "ts-node ../../scripts/package-scripts/clean-model.ts default-model" + "build:cjs": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", + "build:esm": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", + "build:umd": "pnpm run build:umd:tsc && pnpm run build:umd:rollup && pnpm run build:umd:uglify && rimraf ./dist/umd-tmp", + "build:umd:tsc": "tsc -p ./tsconfig.umd.json --outDir ./dist/umd-tmp", + "build:umd:rollup": "rollup -c ../rollup.config.cjs --input ./dist/umd-tmp/models/default-model/src/index.js --file ./dist/umd/index.js --name DefaultUpscalerJSModel --format umd", + "build:umd:uglify": "uglifyjs ./dist/umd/index.js --output ./dist/umd/index.min.js --compress --mangle --source-map" }, "files": [ "assets/**/*", @@ -48,12 +49,14 @@ "@upscalerjs/core": "workspace:*" }, "devDependencies": { + "@rollup/plugin-json": "^6.0.0", + "@tensorflow/tfjs": "~4.8.0", "@tensorflow/tfjs-core": "~4.8.0", "@tensorflow/tfjs-layers": "~4.8.0", - "@tensorflow/tfjs": "~4.8.0", "@tensorflow/tfjs-node": "~4.8.0", "@tensorflow/tfjs-node-gpu": "~4.8.0", - "seedrandom": "3.0.5" + "seedrandom": "3.0.5", + "tsc-alias": "^1.8.7" }, "@upscalerjs": { "title": "Default Model", diff --git a/models/default-model/src/index.ts b/models/default-model/src/index.ts index 4230d33d7..7173b9880 100644 --- a/models/default-model/src/index.ts +++ b/models/default-model/src/index.ts @@ -1,13 +1,13 @@ import { ModelDefinition, } from '@upscalerjs/core'; import { getESRGANModelDefinition, } from '../../../packages/shared/src/esrgan/esrgan'; -import { NAME, VERSION, } from './constants.generated'; +import { name, version, } from '../package.json'; const SCALE = 2; const modelDefinition: ModelDefinition = getESRGANModelDefinition({ scale: SCALE, - name: NAME, - version: VERSION, + name, + version, path: 'models/model.json', meta: { C: 1, diff --git a/models/default-model/tsconfig.cjs.json b/models/default-model/tsconfig.cjs.json index 39d016b9f..f979f1b58 100644 --- a/models/default-model/tsconfig.cjs.json +++ b/models/default-model/tsconfig.cjs.json @@ -1,9 +1,5 @@ { "extends": "../tsconfig.cjs.json", - "compilerOptions": { - "baseUrl": "./src", - "outDir": "./dist/cjs", - }, "include": [ "./src/index.ts", ] diff --git a/models/rollup.config.cjs b/models/rollup.config.cjs new file mode 100644 index 000000000..24c3e813c --- /dev/null +++ b/models/rollup.config.cjs @@ -0,0 +1,20 @@ +const commonjs = require('@rollup/plugin-commonjs'); +const rollupJSON = require('@rollup/plugin-json'); +const { nodeResolve, } = require('@rollup/plugin-node-resolve'); + +module.exports = { + context: 'window', + external: [ + '@tensorflow/tfjs', + ], + plugins: [ + nodeResolve({ + preferBuiltins: true, + resolveOnly: [ + /^(?!.*(@tensorflow\/tfjs))/, + ], + }), + commonjs(), + rollupJSON(), + ], +}; diff --git a/models/tsconfig.cjs.json b/models/tsconfig.cjs.json index d07dff6f0..5a05d67dc 100644 --- a/models/tsconfig.cjs.json +++ b/models/tsconfig.cjs.json @@ -1,8 +1,8 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "moduleResolution": "Node", + "moduleResolution": "Node16", + "module": "CommonJS", "target": "ES5", - "module": "ESNext", - } + }, } diff --git a/models/tsconfig.json b/models/tsconfig.json index 774bce188..4df260be7 100644 --- a/models/tsconfig.json +++ b/models/tsconfig.json @@ -5,6 +5,7 @@ "strict": true, "removeComments": true, "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, "declaration": true, "declarationMap": true, "noUnusedLocals": true, @@ -14,4 +15,5 @@ "noFallthroughCasesInSwitch": true, "rootDirs": ["./src", "../../../packages/shared/src"], }, + "exclude": ["node_modules", "**/*.test.ts"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c95366c3c..2c1704ba3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -526,7 +526,7 @@ importers: version: 20.5.1 '@upscalerjs/default-model': specifier: workspace:* - version: link:../../../models/default-model + version: link:../../../models/default-model/dist/umd-tmp/models/default-model '@upscalerjs/workers.shared': specifier: workspace:* version: link:../shared @@ -620,6 +620,9 @@ importers: specifier: workspace:* version: link:../../packages/core devDependencies: + '@rollup/plugin-json': + specifier: ^6.0.0 + version: 6.0.0(rollup@3.28.0) '@tensorflow/tfjs': specifier: 4.8.0 version: 4.8.0(seedrandom@3.0.5) @@ -638,6 +641,62 @@ importers: seedrandom: specifier: 3.0.5 version: 3.0.5 + tsc-alias: + specifier: ^1.8.7 + version: 1.8.7 + + models/default-model/dist/cjs/models/default-model: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../../../../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ~4.8.0 + version: 4.8.0 + '@tensorflow/tfjs-layers': + specifier: ~4.8.0 + version: 4.8.0(@tensorflow/tfjs-core@4.8.0) + '@tensorflow/tfjs-node': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/default-model/dist/umd-tmp/models/default-model: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../../../../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ~4.8.0 + version: 4.8.0 + '@tensorflow/tfjs-layers': + specifier: ~4.8.0 + version: 4.8.0(@tensorflow/tfjs-core@4.8.0) + '@tensorflow/tfjs-node': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: 4.8.0 + version: 4.8.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + tsc-alias: + specifier: ^1.8.7 + version: 1.8.7 models/esrgan-experiments: dependencies: @@ -813,18 +872,12 @@ importers: packages/upscalerjs: dependencies: - '@tensorflow/tfjs-core': - specifier: ~4.8.0 - version: 4.8.0 - '@tensorflow/tfjs-layers': - specifier: ~4.8.0 - version: 4.8.0(@tensorflow/tfjs-core@4.8.0) '@upscalerjs/core': specifier: workspace:* version: link:../core '@upscalerjs/default-model': specifier: workspace:* - version: link:../../models/default-model + version: link:../../models/default-model/dist/umd-tmp/models/default-model wireit: specifier: ^0.14.0 version: 0.14.0 @@ -872,7 +925,7 @@ importers: version: link:../packages/core '@upscalerjs/default-model': specifier: workspace:* - version: link:../models/default-model + version: link:../models/default-model/dist/umd-tmp/models/default-model '@upscalerjs/esrgan-legacy': specifier: workspace:* version: link:../models/esrgan-legacy @@ -4479,10 +4532,10 @@ packages: resolution: {integrity: sha512-aDF3S3rK9Q2gey/WAttUlISduDItz5BU3306M9Eyv6/oS40aMprnopshtlKTykxRNIBEZuRMaZAnbrQ4QtKGyw==} hasBin: true dependencies: - detect-libc: 2.0.1 + detect-libc: 2.0.2 https-proxy-agent: 5.0.1 make-dir: 3.1.0 - node-fetch: 2.6.12 + node-fetch: 2.6.13 nopt: 5.0.0 npmlog: 5.0.1 rimraf: 3.0.2 @@ -4619,6 +4672,19 @@ packages: rollup: 3.28.0 dev: true + /@rollup/plugin-json@6.0.0(rollup@3.28.0): + resolution: {integrity: sha512-i/4C5Jrdr1XUarRhVu27EEwjt4GObltD7c+MkCIpO2QIbojw8MUs+CCTqOphQi3Qtg1FLmYt+l+6YeoIf51J7w==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.3(rollup@3.28.0) + rollup: 3.28.0 + dev: true + /@rollup/plugin-node-resolve@15.2.0(rollup@3.28.0): resolution: {integrity: sha512-mKur03xNGT8O9ODO6FtT43ITGqHWZbKPdVJHZb+iV9QYcdlhUUB0wgknvA4KCUmC5oHJF6O2W1EgmyOQyVUI4Q==} engines: {node: '>=14.0.0'} @@ -7329,7 +7395,6 @@ packages: /commander@9.5.0: resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} engines: {node: ^12.20.0 || >=14} - dev: false /comment-parser@1.4.0: resolution: {integrity: sha512-QLyTNiZ2KDOibvFPlZ6ZngVsZ/0gYnE6uTXi5aoDg8ed3AkJAz4sEje3Y8a29hQ1s6A99MZXe47fLAXQ1rTqaw==} @@ -8104,14 +8169,9 @@ packages: dependencies: repeat-string: 1.6.1 - /detect-libc@2.0.1: - resolution: {integrity: sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==} - engines: {node: '>=8'} - /detect-libc@2.0.2: resolution: {integrity: sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==} engines: {node: '>=8'} - dev: true /detect-newline@3.1.0: resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==} @@ -12451,7 +12511,6 @@ packages: /mylas@2.1.13: resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==} engines: {node: '>=12.0.0'} - dev: false /nan@2.16.0: resolution: {integrity: sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==} @@ -12545,6 +12604,7 @@ packages: optional: true dependencies: whatwg-url: 5.0.0 + dev: true /node-fetch@2.6.13: resolution: {integrity: sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==} @@ -13255,7 +13315,6 @@ packages: resolution: {integrity: sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==} dependencies: queue-lit: 1.5.0 - dev: false /pngjs@6.0.0: resolution: {integrity: sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==} @@ -13947,7 +14006,6 @@ packages: /queue-lit@1.5.0: resolution: {integrity: sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA==} - dev: false /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -16084,7 +16142,6 @@ packages: mylas: 2.1.13 normalize-path: 3.0.0 plimit-lit: 1.5.0 - dev: false /tslib@2.4.0: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} diff --git a/scripts/package-scripts/scaffold-dependencies.ts b/scripts/package-scripts/scaffold-dependencies.ts index 4f088e7a1..e3a1ab770 100644 --- a/scripts/package-scripts/scaffold-dependencies.ts +++ b/scripts/package-scripts/scaffold-dependencies.ts @@ -12,8 +12,6 @@ export type Platform = 'browser' | 'node' | 'node-gpu'; export type TFJSDependency = '@tensorflow/tfjs' | '@tensorflow/tfjs-node' | '@tensorflow/tfjs-node-gpu'; type ContentFn = (arg: { - tfjs?: TFJSDependency; - platform?: Platform; packageJSON: JSONSchemaForNPMPackageJsonFiles; }) => string; type Content = string | ContentFn; @@ -23,7 +21,6 @@ interface File { } export interface ScaffoldDependenciesConfig { - scaffoldPlatformFiles?: boolean; files: File[]; } @@ -35,13 +32,6 @@ const ROOT = path.resolve(__dirname, `../..`); /**** * Dependency-specific utility functions */ -export const writeTFJSDependency: ContentFn = ({ tfjs, }) => { - if (tfjs === undefined) { - throw new Error('TFJS Platform was undefined'); - } - return `export * as tf from '${tfjs}';`; -}; - export const getPlatformSpecificTensorflow = (platform?: Platform): TFJSDependency | undefined => { if (platform === undefined) { return undefined; @@ -110,32 +100,20 @@ export function loadScaffoldDependenciesConfig(filePath: string): Promise<{ type ScaffoldDependencies = ( packageRoot: string, config: ScaffoldDependenciesConfig, - platform?: Platform, - opts?: { verbose?: boolean }, ) => Promise; const scaffoldDependencies: ScaffoldDependencies = async ( packageRoot, { files, - scaffoldPlatformFiles, }, - platform, { verbose = false } = {}) => { + ) => { const PACKAGE_ROOT = path.resolve(ROOT, packageRoot); const PACKAGE_SRC = path.resolve(PACKAGE_ROOT, 'src'); - if (scaffoldPlatformFiles) { - if (!platform) { - throw new Error('You must provide a platform to scaffold platform specific files'); - } - scaffoldPlatformSpecificFiles(path.resolve(PACKAGE_SRC, 'shared'), platform, { verbose }); - } - const tfjs = getPlatformSpecificTensorflow(platform); const packageJSON = getPackageJSON(PACKAGE_ROOT); files.forEach(({ name, contents }) => { const filePath = path.resolve(PACKAGE_SRC, `${name}.generated.ts`); const lines = contents.map(line => typeof line === 'string' ? line : line({ - tfjs, packageJSON, - platform, })); writeLines(filePath, lines); }); @@ -193,6 +171,6 @@ if (require.main === module) { (async () => { const argv = await getArgs(); const { default: config } = await loadScaffoldDependenciesConfig(path.resolve(ROOT, argv.config)); - await scaffoldDependencies(argv.targetPackage, config, argv.platform); + await scaffoldDependencies(argv.targetPackage, config); })(); } From 6c586c2b66e8e6e1dd105865c1c383e6278b937a Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:43:06 -0400 Subject: [PATCH 02/27] Fix type issue --- models/default-model/src/index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/models/default-model/src/index.ts b/models/default-model/src/index.ts index 7173b9880..9a4eda20e 100644 --- a/models/default-model/src/index.ts +++ b/models/default-model/src/index.ts @@ -1,13 +1,26 @@ import { ModelDefinition, } from '@upscalerjs/core'; import { getESRGANModelDefinition, } from '../../../packages/shared/src/esrgan/esrgan'; -import { name, version, } from '../package.json'; +import packageJSON from '../package.json'; const SCALE = 2; +const isObject = (value: unknown): value is Record => typeof value === 'object' && value !== null; + +const getValue = (packageJSON: unknown, key: string): string => { + if (!isObject(packageJSON)) { + throw new Error('Invalid package json provided'); + } + const value = packageJSON[key]; + if (typeof value !== 'string') { + throw new Error(`value is not a string`); + } + return value; +}; + const modelDefinition: ModelDefinition = getESRGANModelDefinition({ scale: SCALE, - name, - version, + name: getValue(packageJSON, 'name'), + version: getValue(packageJSON, 'version'), path: 'models/model.json', meta: { C: 1, From b983272371b9306eea5bf010b070929fd0a5afb8 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:45:28 -0400 Subject: [PATCH 03/27] Refactor package json to wireit --- models/default-model/package.json | 57 +++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index c45a67c8d..9dae32159 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -24,17 +24,17 @@ } }, "scripts": { - "lint:fix": "pnpm lint --fix", - "lint": "eslint -c ../.eslintrc.js src --ext .ts", - "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", - "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model", - "build": "ts-node ../../scripts/package-scripts/build-model.ts default-model -o cjs -o esm -o umd --skipCheckModelsExist", - "build:cjs": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", - "build:esm": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", - "build:umd": "pnpm run build:umd:tsc && pnpm run build:umd:rollup && pnpm run build:umd:uglify && rimraf ./dist/umd-tmp", - "build:umd:tsc": "tsc -p ./tsconfig.umd.json --outDir ./dist/umd-tmp", - "build:umd:rollup": "rollup -c ../rollup.config.cjs --input ./dist/umd-tmp/models/default-model/src/index.js --file ./dist/umd/index.js --name DefaultUpscalerJSModel --format umd", - "build:umd:uglify": "uglifyjs ./dist/umd/index.js --output ./dist/umd/index.min.js --compress --mangle --source-map" + "lint:fix": "wireit", + "lint": "wireit", + "prepublishOnly": "wireit", + "validate:build": "wireit", + "build": "wireit", + "build:cjs": "wireit", + "build:esm": "wireit", + "build:umd": "wireit", + "build:umd:tsc": "wireit", + "build:umd:rollup": "wireit", + "build:umd:uglify": "wireit" }, "files": [ "assets/**/*", @@ -61,5 +61,40 @@ "@upscalerjs": { "title": "Default Model", "modelFamily": "esrgan" + }, + "wireit": { + "lint:fix": { + "command": "pnpm lint --fix" + }, + "lint": { + "command": "eslint -c ../.eslintrc.js src --ext .ts" + }, + "prepublishOnly": { + "command": "pnpm lint && pnpm build && pnpm validate:build" + }, + "validate:build": { + "command": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model" + }, + "build": { + "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd" + }, + "build:cjs": { + "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src" + }, + "build:esm": { + "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src" + }, + "build:umd": { + "command": "pnpm run build:umd:tsc && pnpm run build:umd:rollup && pnpm run build:umd:uglify && rimraf ./dist/umd-tmp" + }, + "build:umd:tsc": { + "command": "tsc -p ./tsconfig.umd.json --outDir ./dist/umd-tmp" + }, + "build:umd:rollup": { + "command": "rollup -c ../rollup.config.cjs --input ./dist/umd-tmp/models/default-model/src/index.js --file ./dist/umd/index.js --name DefaultUpscalerJSModel --format umd" + }, + "build:umd:uglify": { + "command": "uglifyjs ./dist/umd/index.js --output ./dist/umd/index.min.js --compress --mangle --source-map" + } } } From 8486c65fa22500232dd9797ce3dee814365188fd Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:48:48 -0400 Subject: [PATCH 04/27] Add dependencies for wireit --- models/default-model/package.json | 64 +++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index 9dae32159..bc131b7a2 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -76,16 +76,72 @@ "command": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model" }, "build": { - "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd" + "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd", + "files": [ + "src/**/*.ts", + "!src/**/*.test.ts", + "../../../packages/shared/src/esrgan/**/*.ts", + "package.json", + "tsconfig.cjs.json", + "tsconfig.esm.json", + "tsconfig.umd.json", + "tsconfig.json", + "../tsconfig.cjs.json", + "../tsconfig.esm.json", + "../tsconfig.umd.json", + "../tsconfig.json" + ], + "output": [ + "dist/**" + ] }, "build:cjs": { - "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src" + "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", + "files": [ + "src/**/*.ts", + "!src/**/*.test.ts", + "../../../packages/shared/src/esrgan/**/*.ts", + "package.json", + "tsconfig.cjs.json", + "tsconfig.json", + "../tsconfig.cjs.json", + "../tsconfig.json" + ], + "output": [ + "dist/esm/**" + ] }, "build:esm": { - "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src" + "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", + "files": [ + "src/**/*.ts", + "!src/**/*.test.ts", + "../../../packages/shared/src/esrgan/**/*.ts", + "package.json", + "tsconfig.esm.json", + "tsconfig.json", + "../tsconfig.esm.json", + "../tsconfig.json" + ], + "output": [ + "dist/esm/**" + ] }, "build:umd": { - "command": "pnpm run build:umd:tsc && pnpm run build:umd:rollup && pnpm run build:umd:uglify && rimraf ./dist/umd-tmp" + "command": "pnpm run build:umd:tsc && pnpm run build:umd:rollup && pnpm run build:umd:uglify && rimraf ./dist/umd-tmp", + "files": [ + "src/**/*.ts", + "!src/**/*.test.ts", + "../../../packages/shared/src/esrgan/**/*.ts", + "package.json", + "tsconfig.umd.json", + "tsconfig.json", + "../tsconfig.umd.json", + "../tsconfig.json" + ], + "output": [ + "dist/umd/**" + ] }, "build:umd:tsc": { "command": "tsc -p ./tsconfig.umd.json --outDir ./dist/umd-tmp" From 7447623a65e713a4301cca777ab0fbaf648422c1 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:52:05 -0400 Subject: [PATCH 05/27] Fix deep source issue and remove lint fix commands --- models/default-model/package.json | 3 --- models/default-model/src/index.ts | 2 +- packages/upscalerjs/package.json | 12 ------------ 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index bc131b7a2..5cae1d404 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -63,9 +63,6 @@ "modelFamily": "esrgan" }, "wireit": { - "lint:fix": { - "command": "pnpm lint --fix" - }, "lint": { "command": "eslint -c ../.eslintrc.js src --ext .ts" }, diff --git a/models/default-model/src/index.ts b/models/default-model/src/index.ts index 9a4eda20e..22ecec8f6 100644 --- a/models/default-model/src/index.ts +++ b/models/default-model/src/index.ts @@ -12,7 +12,7 @@ const getValue = (packageJSON: unknown, key: string): string => { } const value = packageJSON[key]; if (typeof value !== 'string') { - throw new Error(`value is not a string`); + throw new Error('value is not a string'); } return value; }; diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 3db65f4a7..4f2099445 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -167,21 +167,12 @@ "lint": { "command": "pnpm lint:browser && pnpm lint:node" }, - "lint:fix": { - "command": "pnpm lint:browser:fix && pnpm lint:node:fix" - }, "lint:browser": { "command": "eslint -c .eslintrc.js src --ext .ts --ignore-pattern '**/*.node.ts'" }, - "lint:browser:fix": { - "command": "eslint -c .eslintrc.js src --ext .ts --ignore-pattern '**/*.node.ts' --fix" - }, "lint:node": { "command": "eslint -c .eslintrc.js src --ext .ts --ignore-pattern '**/*.browser.ts'" }, - "lint:node:fix": { - "command": "eslint -c .eslintrc.js src --ext .ts --ignore-pattern '**/*.browser.ts' --fix" - }, "test:unit:browser:playwright": { "command": "playwright-test --config playwright.config.json" }, @@ -210,11 +201,8 @@ "prepublishOnly": "wireit", "format": "wireit", "lint": "wireit", - "lint:fix": "wireit", "lint:browser": "wireit", - "lint:browser:fix": "wireit", "lint:node": "wireit", - "lint:node:fix": "wireit", "test:unit:browser:playwright": "wireit", "test:unit:browser:vite": "wireit", "test:unit:node": "wireit", From 6a92ae70d55f1ab1e1ddfda1d5a3f2a2e27351b9 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:56:36 -0400 Subject: [PATCH 06/27] Fix post install script --- models/default-model/package.json | 3 +++ package.json | 3 ++- pnpm-lock.yaml | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index 5cae1d404..a524c7b0f 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -74,6 +74,9 @@ }, "build": { "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd", + "dependencies": [ + "../../packages/core:build" + ], "files": [ "src/**/*.ts", "!src/**/*.test.ts", diff --git a/package.json b/package.json index 95f8a4d92..9d940c4ff 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,8 @@ "command": "pnpm --filter=!\"@upscalerjs/docs\" --filter=!\"@upscalerjs/examples.*\" install" }, "postinstall": { - "command": "pnpm --filter @upscalerjs/core --filter @upscalerjs/default-model build" + "command": "cd models/default-model && pnpm build", + "oldcommand": "pnpm --filter @upscalerjs/default-model build" }, "update:dependency": { "command": "pnpm --filter @upscalerjs/scripts update:dependency" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c1704ba3..f6ec8bfa9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -526,7 +526,7 @@ importers: version: 20.5.1 '@upscalerjs/default-model': specifier: workspace:* - version: link:../../../models/default-model/dist/umd-tmp/models/default-model + version: link:../../../models/default-model/dist/esm/models/default-model '@upscalerjs/workers.shared': specifier: workspace:* version: link:../shared @@ -651,6 +651,9 @@ importers: specifier: workspace:* version: link:../../../../../../packages/core devDependencies: + '@rollup/plugin-json': + specifier: ^6.0.0 + version: 6.0.0(rollup@3.28.0) '@tensorflow/tfjs': specifier: 4.8.0 version: 4.8.0(seedrandom@3.0.5) @@ -669,13 +672,19 @@ importers: seedrandom: specifier: 3.0.5 version: 3.0.5 + tsc-alias: + specifier: ^1.8.7 + version: 1.8.7 - models/default-model/dist/umd-tmp/models/default-model: + models/default-model/dist/esm/models/default-model: dependencies: '@upscalerjs/core': specifier: workspace:* version: link:../../../../../../packages/core devDependencies: + '@rollup/plugin-json': + specifier: ^6.0.0 + version: 6.0.0(rollup@3.28.0) '@tensorflow/tfjs': specifier: 4.8.0 version: 4.8.0(seedrandom@3.0.5) @@ -877,7 +886,7 @@ importers: version: link:../core '@upscalerjs/default-model': specifier: workspace:* - version: link:../../models/default-model/dist/umd-tmp/models/default-model + version: link:../../models/default-model/dist/esm/models/default-model wireit: specifier: ^0.14.0 version: 0.14.0 @@ -925,7 +934,7 @@ importers: version: link:../packages/core '@upscalerjs/default-model': specifier: workspace:* - version: link:../models/default-model/dist/umd-tmp/models/default-model + version: link:../models/default-model/dist/esm/models/default-model '@upscalerjs/esrgan-legacy': specifier: workspace:* version: link:../models/esrgan-legacy From 45ae8568703ba36e4c4306bfb86be6b66e761454 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:30:10 -0400 Subject: [PATCH 07/27] Avoid linting from package json in dist --- models/default-model/package.json | 1 - models/default-model/tsconfig.esm.json | 4 ---- models/default-model/tsconfig.umd.json | 4 ---- package.json | 2 +- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index a524c7b0f..8be78f9a8 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -24,7 +24,6 @@ } }, "scripts": { - "lint:fix": "wireit", "lint": "wireit", "prepublishOnly": "wireit", "validate:build": "wireit", diff --git a/models/default-model/tsconfig.esm.json b/models/default-model/tsconfig.esm.json index 07884a3ad..0b8c130e4 100644 --- a/models/default-model/tsconfig.esm.json +++ b/models/default-model/tsconfig.esm.json @@ -1,9 +1,5 @@ { "extends": "../tsconfig.esm.json", - "compilerOptions": { - "baseUrl": "./src", - "outDir": "./dist/esm", - }, "include": [ "./src/index.ts", ] diff --git a/models/default-model/tsconfig.umd.json b/models/default-model/tsconfig.umd.json index 5b845ffed..7d7e0b242 100644 --- a/models/default-model/tsconfig.umd.json +++ b/models/default-model/tsconfig.umd.json @@ -1,9 +1,5 @@ { "extends": "../tsconfig.umd.json", - "compilerOptions": { - "baseUrl": "./src", - "outDir": "./dist/tmp", - }, "include": [ "./src/index.ts", ] diff --git a/package.json b/package.json index 9d940c4ff..bc9dabaf1 100644 --- a/package.json +++ b/package.json @@ -197,7 +197,7 @@ "command": "pnpm --filter @upscalerjs/scripts example:start" }, "lint": { - "command": "pnpm --filter upscaler --filter @upscalerjs/* lint" + "command": "pnpm --filter=!./models/**/dist/** lint" }, "model:build": { "command": "pnpm --filter @upscalerjs/scripts model:build" From 1a97108f84bf3d312794d91b43494017d4b4403a Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:30:55 -0400 Subject: [PATCH 08/27] Run lint in parallel --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc9dabaf1..46f2f7ad0 100644 --- a/package.json +++ b/package.json @@ -197,7 +197,7 @@ "command": "pnpm --filter @upscalerjs/scripts example:start" }, "lint": { - "command": "pnpm --filter=!./models/**/dist/** lint" + "command": "pnpm --parallel --filter=!./models/**/dist/** lint" }, "model:build": { "command": "pnpm --filter @upscalerjs/scripts model:build" From 94bc89f3438fa4cfcf883eee8283b386d43e0a69 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:29:12 -0400 Subject: [PATCH 09/27] Fix constants generation --- models/default-model/package.json | 21 +++-- models/default-model/src/index.ts | 21 ++--- models/default-model/tsconfig.json | 2 +- package.json | 5 +- packages/upscalerjs/package.json | 20 ++++- .../upscalerjs/src/shared/upscaler.test.ts | 26 ------ pnpm-lock.yaml | 83 ++++--------------- test/integration/browser/speed.ts | 4 +- 8 files changed, 58 insertions(+), 124 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index 8be78f9a8..628e0f0ac 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -54,8 +54,8 @@ "@tensorflow/tfjs-layers": "~4.8.0", "@tensorflow/tfjs-node": "~4.8.0", "@tensorflow/tfjs-node-gpu": "~4.8.0", - "seedrandom": "3.0.5", - "tsc-alias": "^1.8.7" + "babel-plugin-transform-inline-environment-variables": "^0.4.4", + "seedrandom": "3.0.5" }, "@upscalerjs": { "title": "Default Model", @@ -71,14 +71,22 @@ "validate:build": { "command": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model" }, + "scaffold": { + "command": "node -e 'const fs = require(\"fs\"); const {name, version} = require(\"./package.json\"); fs.writeFileSync(\"./src/constants.generated.ts\", `export const NAME = \"${name}\";\\nexport const VERSION=\"${version}\"`, \"utf-8\");'" + }, "build": { - "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd", + "command": "echo 1", "dependencies": [ - "../../packages/core:build" + "../../packages/core:build", + "scaffold", + "build:cjs", + "build:esm", + "build:umd" ], "files": [ "src/**/*.ts", "!src/**/*.test.ts", + "!src/**/*.generated.ts", "../../../packages/shared/src/esrgan/**/*.ts", "package.json", "tsconfig.cjs.json", @@ -95,10 +103,11 @@ ] }, "build:cjs": { - "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", + "command": "NAME=@upscalerjs/default-model VERSION=1.0.0-beta.15 tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "files": [ "src/**/*.ts", "!src/**/*.test.ts", + "!src/**/*.generated.ts", "../../../packages/shared/src/esrgan/**/*.ts", "package.json", "tsconfig.cjs.json", @@ -115,6 +124,7 @@ "files": [ "src/**/*.ts", "!src/**/*.test.ts", + "!src/**/*.generated.ts", "../../../packages/shared/src/esrgan/**/*.ts", "package.json", "tsconfig.esm.json", @@ -131,6 +141,7 @@ "files": [ "src/**/*.ts", "!src/**/*.test.ts", + "!src/**/*.generated.ts", "../../../packages/shared/src/esrgan/**/*.ts", "package.json", "tsconfig.umd.json", diff --git a/models/default-model/src/index.ts b/models/default-model/src/index.ts index 22ecec8f6..652ab4fd8 100644 --- a/models/default-model/src/index.ts +++ b/models/default-model/src/index.ts @@ -1,26 +1,15 @@ import { ModelDefinition, } from '@upscalerjs/core'; import { getESRGANModelDefinition, } from '../../../packages/shared/src/esrgan/esrgan'; -import packageJSON from '../package.json'; +import { NAME, VERSION, } from './constants.generated'; const SCALE = 2; -const isObject = (value: unknown): value is Record => typeof value === 'object' && value !== null; - -const getValue = (packageJSON: unknown, key: string): string => { - if (!isObject(packageJSON)) { - throw new Error('Invalid package json provided'); - } - const value = packageJSON[key]; - if (typeof value !== 'string') { - throw new Error('value is not a string'); - } - return value; -}; - const modelDefinition: ModelDefinition = getESRGANModelDefinition({ scale: SCALE, - name: getValue(packageJSON, 'name'), - version: getValue(packageJSON, 'version'), + // name: getValue(packageJSON, 'name'), + // version: getValue(packageJSON, 'version'), + name: NAME, + version: VERSION, path: 'models/model.json', meta: { C: 1, diff --git a/models/default-model/tsconfig.json b/models/default-model/tsconfig.json index 035ddfff6..d6a1a7eb8 100644 --- a/models/default-model/tsconfig.json +++ b/models/default-model/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.json", - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "src/foo.js"], "exclude": ["node_modules", "**/*.test.ts"], "compilerOptions": { "rootDirs": ["./src", "../../../packages/shared/src"], diff --git a/package.json b/package.json index 46f2f7ad0..d8bd5c206 100644 --- a/package.json +++ b/package.json @@ -178,8 +178,9 @@ "command": "pnpm --filter=!\"@upscalerjs/docs\" --filter=!\"@upscalerjs/examples.*\" install" }, "postinstall": { - "command": "cd models/default-model && pnpm build", - "oldcommand": "pnpm --filter @upscalerjs/default-model build" + "dependencies": [ + "./models/default-model:build" + ] }, "update:dependency": { "command": "pnpm --filter @upscalerjs/scripts update:dependency" diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 4f2099445..368016eeb 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -46,10 +46,13 @@ ], "wireit": { "build": { - "command": "pnpm run build:node-gpu && pnpm run build:node && pnpm run build:browser", + "command": "echo '1'", "dependencies": [ "../core:build", - "../../models/default-model:build" + "../../models/default-model:build", + "build:node-gpu", + "build:node", + "build:browser" ], "files": [ "src/**/*.ts", @@ -82,7 +85,12 @@ ] }, "build:browser:umd": { - "command": "pnpm run build:browser:umd:tsc && pnpm run build:browser:umd:rollup && pnpm run build:browser:umd:uglify && rimraf ./dist/browser/tmp", + "command": "rimraf ./dist/browser/tmp", + "dependencies": [ + "build:browser:umd:tsc", + "build:browser:umd:rollup", + "build:browser:umd:uglify" + ], "files": [ "src/shared/**/*.ts", "src/browser/**/*.ts", @@ -106,7 +114,11 @@ "command": "uglifyjs ./dist/browser/umd/upscaler.js --output ./dist/browser/umd/upscaler.min.js --compress --mangle --source-map" }, "build:browser": { - "command": "pnpm run build:browser:esm && pnpm run build:browser:umd", + "command": "echo '1'", + "dependencies": [ + "build:browser:esm", + "build:browser:umd" + ], "files": [ "src/shared/**/*.ts", "src/browser/**/*.ts", diff --git a/packages/upscalerjs/src/shared/upscaler.test.ts b/packages/upscalerjs/src/shared/upscaler.test.ts index 837624a1f..7ff6ffcee 100644 --- a/packages/upscalerjs/src/shared/upscaler.test.ts +++ b/packages/upscalerjs/src/shared/upscaler.test.ts @@ -17,23 +17,10 @@ import { Input, } from '../node/image.node'; import { loadModel as _loadModel, } from '../node/loadModel.node'; -// import { tf, } from './dependencies.generated'; -// import { loadModel } from './loadModel.generated'; -// import { getImageAsTensor } from './image.generated'; -// import type * as imageGenerated from './image.generated'; -// import type * as loadModelGenerated from './loadModel.generated'; import type * as upscale from './upscale'; import type * as modelUtils from './model-utils'; import type * as warmup from './warmup'; -import type * as dependenciesGenerated from './dependencies.generated'; -// vi.mock('./image.generated', async () => { -// const { getImageAsTensor, ...rest } = await vi.importActual('./image.generated') as typeof imageGenerated; -// return { -// ...rest, -// getImageAsTensor: vi.fn(getImageAsTensor), -// }; -// }); vi.mock('./upscale', async () => { const { cancellableUpscale, ...rest } = await vi.importActual('./upscale') as typeof upscale; return { @@ -41,13 +28,6 @@ vi.mock('./upscale', async () => { cancellableUpscale: vi.fn(cancellableUpscale), }; }); -// vi.mock('./loadModel.generated', async () => { -// const { loadModel, ...rest } = await vi.importActual('./loadModel.generated') as typeof loadModelGenerated; -// return { -// ...rest, -// loadModel: vi.fn(loadModel), -// }; -// }); vi.mock('./model-utils', async () => { const { getModel, ...rest } = await vi.importActual('./model-utils') as typeof modelUtils; return { @@ -62,12 +42,6 @@ vi.mock('./warmup', async () => { cancellableWarmup: vi.fn(cancellableWarmup), }; }); -// vi.mock('./dependencies.generated', async () => { -// const dependencies = await vi.importActual('./dependencies.generated') as typeof dependenciesGenerated; -// return { -// ...dependencies, -// }; -// }); const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f6ec8bfa9..66b3b3768 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -526,7 +526,7 @@ importers: version: 20.5.1 '@upscalerjs/default-model': specifier: workspace:* - version: link:../../../models/default-model/dist/esm/models/default-model + version: link:../../../models/default-model '@upscalerjs/workers.shared': specifier: workspace:* version: link:../shared @@ -638,74 +638,12 @@ importers: '@tensorflow/tfjs-node-gpu': specifier: 4.8.0 version: 4.8.0(seedrandom@3.0.5) + babel-plugin-transform-inline-environment-variables: + specifier: ^0.4.4 + version: 0.4.4 seedrandom: specifier: 3.0.5 version: 3.0.5 - tsc-alias: - specifier: ^1.8.7 - version: 1.8.7 - - models/default-model/dist/cjs/models/default-model: - dependencies: - '@upscalerjs/core': - specifier: workspace:* - version: link:../../../../../../packages/core - devDependencies: - '@rollup/plugin-json': - specifier: ^6.0.0 - version: 6.0.0(rollup@3.28.0) - '@tensorflow/tfjs': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - '@tensorflow/tfjs-core': - specifier: ~4.8.0 - version: 4.8.0 - '@tensorflow/tfjs-layers': - specifier: ~4.8.0 - version: 4.8.0(@tensorflow/tfjs-core@4.8.0) - '@tensorflow/tfjs-node': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - '@tensorflow/tfjs-node-gpu': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - seedrandom: - specifier: 3.0.5 - version: 3.0.5 - tsc-alias: - specifier: ^1.8.7 - version: 1.8.7 - - models/default-model/dist/esm/models/default-model: - dependencies: - '@upscalerjs/core': - specifier: workspace:* - version: link:../../../../../../packages/core - devDependencies: - '@rollup/plugin-json': - specifier: ^6.0.0 - version: 6.0.0(rollup@3.28.0) - '@tensorflow/tfjs': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - '@tensorflow/tfjs-core': - specifier: ~4.8.0 - version: 4.8.0 - '@tensorflow/tfjs-layers': - specifier: ~4.8.0 - version: 4.8.0(@tensorflow/tfjs-core@4.8.0) - '@tensorflow/tfjs-node': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - '@tensorflow/tfjs-node-gpu': - specifier: 4.8.0 - version: 4.8.0(seedrandom@3.0.5) - seedrandom: - specifier: 3.0.5 - version: 3.0.5 - tsc-alias: - specifier: ^1.8.7 - version: 1.8.7 models/esrgan-experiments: dependencies: @@ -886,7 +824,7 @@ importers: version: link:../core '@upscalerjs/default-model': specifier: workspace:* - version: link:../../models/default-model/dist/esm/models/default-model + version: link:../../models/default-model wireit: specifier: ^0.14.0 version: 0.14.0 @@ -934,7 +872,7 @@ importers: version: link:../packages/core '@upscalerjs/default-model': specifier: workspace:* - version: link:../models/default-model/dist/esm/models/default-model + version: link:../models/default-model '@upscalerjs/esrgan-legacy': specifier: workspace:* version: link:../models/esrgan-legacy @@ -6494,6 +6432,10 @@ packages: transitivePeerDependencies: - supports-color + /babel-plugin-transform-inline-environment-variables@0.4.4: + resolution: {integrity: sha512-bJILBtn5a11SmtR2j/3mBOjX4K3weC6cq+NNZ7hG22wCAqpc3qtj/iN7dSe9HDiS46lgp1nHsQgeYrea/RUe+g==} + dev: true + /babel-preset-current-node-syntax@1.0.1(@babel/core@7.22.10): resolution: {integrity: sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ==} peerDependencies: @@ -7404,6 +7346,7 @@ packages: /commander@9.5.0: resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} engines: {node: ^12.20.0 || >=14} + dev: false /comment-parser@1.4.0: resolution: {integrity: sha512-QLyTNiZ2KDOibvFPlZ6ZngVsZ/0gYnE6uTXi5aoDg8ed3AkJAz4sEje3Y8a29hQ1s6A99MZXe47fLAXQ1rTqaw==} @@ -12520,6 +12463,7 @@ packages: /mylas@2.1.13: resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==} engines: {node: '>=12.0.0'} + dev: false /nan@2.16.0: resolution: {integrity: sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==} @@ -13324,6 +13268,7 @@ packages: resolution: {integrity: sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==} dependencies: queue-lit: 1.5.0 + dev: false /pngjs@6.0.0: resolution: {integrity: sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==} @@ -14015,6 +13960,7 @@ packages: /queue-lit@1.5.0: resolution: {integrity: sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA==} + dev: false /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -16151,6 +16097,7 @@ packages: mylas: 2.1.13 normalize-path: 3.0.0 plimit-lit: 1.5.0 + dev: false /tslib@2.4.0: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} diff --git a/test/integration/browser/speed.ts b/test/integration/browser/speed.ts index e00466666..ab6ccc617 100644 --- a/test/integration/browser/speed.ts +++ b/test/integration/browser/speed.ts @@ -109,7 +109,7 @@ describe('Speed Integration Tests', () => { if (output !== undefined) { output.dispose(); } - return [rawDuration, upscalerJSDuration] as [number, number]; + return [rawDuration, upscalerJSDuration]; }); }); }); @@ -168,7 +168,7 @@ describe('Speed Integration Tests', () => { if (output !== undefined) { output.dispose(); } - return [rawDuration, upscalerJSDuration] as [number, number]; + return [rawDuration, upscalerJSDuration]; }); }); }); From 17eb4c79c82287f0137901337d3f6571f29b786a Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:32:14 -0400 Subject: [PATCH 10/27] Fix issue with wireit colliding with fs.writeFileSync --- models/default-model/package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index 628e0f0ac..aedcecd3d 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -72,7 +72,13 @@ "command": "ts-node ../../scripts/package-scripts/validate-build.ts models/default-model" }, "scaffold": { - "command": "node -e 'const fs = require(\"fs\"); const {name, version} = require(\"./package.json\"); fs.writeFileSync(\"./src/constants.generated.ts\", `export const NAME = \"${name}\";\\nexport const VERSION=\"${version}\"`, \"utf-8\");'" + "command": "node -e 'const fs = require(\"fs\"); const {name, version} = require(\"./package.json\"); fs.writeFileSync(\"./src/constants.generated.ts\", `export const NAME = \"${name}\";\\nexport const VERSION=\"${version}\"`, \"utf-8\");'", + "files": [ + "package.json" + ], + "output": [ + "./src/constants.generated.ts" + ] }, "build": { "command": "echo 1", From 1c0a5dbc9d6ab2c77b702e6ad37305859c2bc4cf Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:43:33 -0400 Subject: [PATCH 11/27] Set up tmate --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b6518f62..9fef69370 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,6 +17,11 @@ jobs: with: node-version: 16 + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + with: + detached: true + - name: 'Lint' run: 'pnpm lint' @@ -169,11 +174,6 @@ jobs: with: gdrive_credentials_data: ${{ secrets.GDRIVE_CREDENTIALS_DATA }} - # - name: Setup tmate session - # uses: mxschmitt/action-tmate@v3 - # with: - # detached: true - - name: 'Build Models' run: pnpm test:integration:browser -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle From f772db30b890e5535903b29f1263985a4bd6fba4 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:44:55 -0400 Subject: [PATCH 12/27] Move tmate above pnpm --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9fef69370..712b628ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,16 +12,16 @@ jobs: - name: 'Checkout repository' uses: actions/checkout@v2 - - name: 'Setup PNPM with Node 16' - uses: ./.github/actions/setup-pnpm - with: - node-version: 16 - - name: Setup tmate session uses: mxschmitt/action-tmate@v3 with: detached: true + - name: 'Setup PNPM with Node 16' + uses: ./.github/actions/setup-pnpm + with: + node-version: 16 + - name: 'Lint' run: 'pnpm lint' From 3c96b0a2172d662584c8d24636bc0016348ea8b3 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:50:18 -0400 Subject: [PATCH 13/27] Clean up core package json --- packages/core/package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 8743c25ac..02a519826 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -28,7 +28,12 @@ "command": "ts-node ../../scripts/package-scripts/validate-build.ts packages/core -c './dist/esm/index.d.ts' -c './dist/cjs/index.d.ts' " }, "build": { - "command": "pnpm build:esm && pnpm build:cjs && pnpm validate", + "command": "echo 1", + "dependencies": [ + "build:esm", + "build:cjs", + "validate" + ], "files": [ "src/**/*.ts", "!src/**/*.test.ts", From cd46fcf635f24708c3f6964be928fcea2b77cca5 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:50:49 -0400 Subject: [PATCH 14/27] Build core before building default model --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d8bd5c206..ef27ef806 100644 --- a/package.json +++ b/package.json @@ -179,6 +179,7 @@ }, "postinstall": { "dependencies": [ + "./packages/core:build", "./models/default-model:build" ] }, From 74f61609281a492f92aee7d610fc8d11db0b6431 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Wed, 4 Oct 2023 19:00:13 -0400 Subject: [PATCH 15/27] Do not specify scripts as dependencies --- models/default-model/package.json | 9 +++------ package.json | 2 +- packages/core/package.json | 7 +------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index aedcecd3d..8ddcd76e2 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -81,13 +81,10 @@ ] }, "build": { - "command": "echo 1", + "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd", "dependencies": [ "../../packages/core:build", - "scaffold", - "build:cjs", - "build:esm", - "build:umd" + "scaffold" ], "files": [ "src/**/*.ts", @@ -109,7 +106,7 @@ ] }, "build:cjs": { - "command": "NAME=@upscalerjs/default-model VERSION=1.0.0-beta.15 tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", + "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "files": [ "src/**/*.ts", "!src/**/*.test.ts", diff --git a/package.json b/package.json index ef27ef806..606083fef 100644 --- a/package.json +++ b/package.json @@ -226,7 +226,7 @@ ] }, "test:integration:node": { - "command": "echo 1", + "command": "pnpm --filter @upscalerjs/scripts test:integration:node", "dependencies": [ "./packages/upscalerjs:build:node-gpu", "./packages/upscalerjs:build:node" diff --git a/packages/core/package.json b/packages/core/package.json index 02a519826..8743c25ac 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -28,12 +28,7 @@ "command": "ts-node ../../scripts/package-scripts/validate-build.ts packages/core -c './dist/esm/index.d.ts' -c './dist/cjs/index.d.ts' " }, "build": { - "command": "echo 1", - "dependencies": [ - "build:esm", - "build:cjs", - "validate" - ], + "command": "pnpm build:esm && pnpm build:cjs && pnpm validate", "files": [ "src/**/*.ts", "!src/**/*.test.ts", From 781d6ec9a1de56d5180219a777006e9d03274883 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:49:06 -0400 Subject: [PATCH 16/27] Move more wireit scripts out of deps --- packages/upscalerjs/package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 368016eeb..67c293168 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -114,11 +114,7 @@ "command": "uglifyjs ./dist/browser/umd/upscaler.js --output ./dist/browser/umd/upscaler.min.js --compress --mangle --source-map" }, "build:browser": { - "command": "echo '1'", - "dependencies": [ - "build:browser:esm", - "build:browser:umd" - ], + "command": "pnpm build:browser:esm && pnpm build:browser:umd", "files": [ "src/shared/**/*.ts", "src/browser/**/*.ts", From 37aa37fbd5663db21ae96d695622f9274be11b84 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:51:28 -0400 Subject: [PATCH 17/27] Move more wireit scripts out of deps in umd --- packages/upscalerjs/package.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 67c293168..3ca0df2db 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -85,12 +85,7 @@ ] }, "build:browser:umd": { - "command": "rimraf ./dist/browser/tmp", - "dependencies": [ - "build:browser:umd:tsc", - "build:browser:umd:rollup", - "build:browser:umd:uglify" - ], + "command": "pnpm build:browser:umd:tsc pnpm build:browser:umd:rollup pnpm build:browser:umd:uglify rimraf ./dist/browser/tmp", "files": [ "src/shared/**/*.ts", "src/browser/**/*.ts", From e54ff6100cc37eb850c505e7363e6ccfe2b51521 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:02:56 -0400 Subject: [PATCH 18/27] Fix bundling path --- test/lib/umd/prepare.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/umd/prepare.ts b/test/lib/umd/prepare.ts index da851ccc6..e9344bd88 100644 --- a/test/lib/umd/prepare.ts +++ b/test/lib/umd/prepare.ts @@ -78,7 +78,7 @@ const getMinifiedScripts = () => { export const prepareScriptBundleForUMD = async () => { rimraf(DIST); mkdirpSync(DIST); - copyFileSync(path.join(UPSCALER_PATH, 'dist/browser/umd/upscaler.min.js'), path.join(DIST, 'upscaler.min.js')) + copyFileSync(path.join(UPSCALER_PATH, 'dist/umd/upscaler.min.js'), path.join(DIST, 'upscaler.min.js')) copyAllModels(); From 4bcc48310ce51c98f030a290c0da41aed45166d4 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:39:35 -0400 Subject: [PATCH 19/27] Clean up wireit dependencies --- packages/upscalerjs/package.json | 39 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 3ca0df2db..24100da60 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -46,13 +46,10 @@ ], "wireit": { "build": { - "command": "echo '1'", + "command": "pnpm build:node-gpu && pnpm build:node && pnpm build:browser", "dependencies": [ "../core:build", - "../../models/default-model:build", - "build:node-gpu", - "build:node", - "build:browser" + "../../models/default-model:build" ], "files": [ "src/**/*.ts", @@ -69,6 +66,22 @@ "dist/**" ] }, + "build:browser": { + "command": "pnpm build:browser:esm && pnpm build:browser:umd", + "files": [ + "src/shared/**/*.ts", + "src/browser/**/*.ts", + "!src/**/*.test.ts", + "package.json", + "vite.config.ts", + "tsconfig.browser.esm.json", + "tsconfig.browser.umd.json", + "tsconfig.json" + ], + "output": [ + "dist/browser/**" + ] + }, "build:browser:esm": { "command": "tsc -p ./tsconfig.browser.esm.json --outDir ./dist/browser/esm", "files": [ @@ -108,22 +121,6 @@ "build:browser:umd:uglify": { "command": "uglifyjs ./dist/browser/umd/upscaler.js --output ./dist/browser/umd/upscaler.min.js --compress --mangle --source-map" }, - "build:browser": { - "command": "pnpm build:browser:esm && pnpm build:browser:umd", - "files": [ - "src/shared/**/*.ts", - "src/browser/**/*.ts", - "!src/**/*.test.ts", - "package.json", - "vite.config.ts", - "tsconfig.browser.esm.json", - "tsconfig.browser.umd.json", - "tsconfig.json" - ], - "output": [ - "dist/browser/**" - ] - }, "build:node": { "command": "tsc -p ./tsconfig.node.cjs.json --outDir ./dist/node", "files": [ From eca9eff90d3cecb18523aa1b1521f1f0ed2538c1 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:41:41 -0400 Subject: [PATCH 20/27] Fix UMD path again --- test/lib/umd/prepare.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/umd/prepare.ts b/test/lib/umd/prepare.ts index e9344bd88..da851ccc6 100644 --- a/test/lib/umd/prepare.ts +++ b/test/lib/umd/prepare.ts @@ -78,7 +78,7 @@ const getMinifiedScripts = () => { export const prepareScriptBundleForUMD = async () => { rimraf(DIST); mkdirpSync(DIST); - copyFileSync(path.join(UPSCALER_PATH, 'dist/umd/upscaler.min.js'), path.join(DIST, 'upscaler.min.js')) + copyFileSync(path.join(UPSCALER_PATH, 'dist/browser/umd/upscaler.min.js'), path.join(DIST, 'upscaler.min.js')) copyAllModels(); From 9dbc775712161bcc95eb1de641c298fdfc2fcff8 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:43:56 -0400 Subject: [PATCH 21/27] Fix bad command --- packages/upscalerjs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index 24100da60..09792e7d4 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -98,7 +98,7 @@ ] }, "build:browser:umd": { - "command": "pnpm build:browser:umd:tsc pnpm build:browser:umd:rollup pnpm build:browser:umd:uglify rimraf ./dist/browser/tmp", + "command": "pnpm build:browser:umd:tsc && pnpm build:browser:umd:rollup && pnpm build:browser:umd:uglify && rimraf ./dist/browser/tmp", "files": [ "src/shared/**/*.ts", "src/browser/**/*.ts", From 22d0ae4948b344d8efaa9724c0ce9be5da776fe8 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:46:51 -0400 Subject: [PATCH 22/27] Remove bad types --- test/integration/browser/speed.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/browser/speed.ts b/test/integration/browser/speed.ts index ab6ccc617..e00466666 100644 --- a/test/integration/browser/speed.ts +++ b/test/integration/browser/speed.ts @@ -109,7 +109,7 @@ describe('Speed Integration Tests', () => { if (output !== undefined) { output.dispose(); } - return [rawDuration, upscalerJSDuration]; + return [rawDuration, upscalerJSDuration] as [number, number]; }); }); }); @@ -168,7 +168,7 @@ describe('Speed Integration Tests', () => { if (output !== undefined) { output.dispose(); } - return [rawDuration, upscalerJSDuration]; + return [rawDuration, upscalerJSDuration] as [number, number]; }); }); }); From 0c6cd2a2c1c42d98f22fa04288f056330a48f049 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:13:08 -0400 Subject: [PATCH 23/27] Try specifying entry points for default model --- models/default-model/package.json | 9 +++------ models/default-model/src/cjs.ts | 2 ++ models/default-model/src/esm.ts | 1 + test/integration/model/model.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 models/default-model/src/cjs.ts create mode 100644 models/default-model/src/esm.ts diff --git a/models/default-model/package.json b/models/default-model/package.json index ad9ebb1de..2037cce3f 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -19,8 +19,8 @@ }, "exports": { ".": { - "require": "./dist/cjs/models/default-model/src/index.js", - "import": "./dist/esm/models/default-model/src/index.js" + "require": "./dist/cjs/models/default-model/src/cjs.js", + "import": "./dist/esm/models/default-model/src/esm.js" } }, "scripts": { @@ -30,10 +30,7 @@ "build": "wireit", "build:cjs": "wireit", "build:esm": "wireit", - "build:umd": "wireit", - "build:umd:tsc": "wireit", - "build:umd:rollup": "wireit", - "build:umd:uglify": "wireit" + "build:umd": "wireit" }, "files": [ "assets/**/*", diff --git a/models/default-model/src/cjs.ts b/models/default-model/src/cjs.ts new file mode 100644 index 000000000..4f48ee1ff --- /dev/null +++ b/models/default-model/src/cjs.ts @@ -0,0 +1,2 @@ +import { default as DefaultModel, } from './index'; +module.exports = DefaultModel; // eslint-disable-line diff --git a/models/default-model/src/esm.ts b/models/default-model/src/esm.ts new file mode 100644 index 000000000..00aed3bed --- /dev/null +++ b/models/default-model/src/esm.ts @@ -0,0 +1 @@ +export { default as default, } from './index'; diff --git a/test/integration/model/model.ts b/test/integration/model/model.ts index 870c639d6..5e33e2d47 100644 --- a/test/integration/model/model.ts +++ b/test/integration/model/model.ts @@ -25,7 +25,7 @@ const JEST_TIMEOUT = 60 * 1000 * 15 * 2; jest.setTimeout(JEST_TIMEOUT); jest.retryTimes(0); -const SPECIFIC_PACKAGE: string | undefined = 'default-model'; +const SPECIFIC_PACKAGE: string | undefined = undefined; const SPECIFIC_MODEL: string | undefined = undefined; console.log('***** PLATFORMS', PLATFORMS) From 1c74d5fe1c993892994d043763f9845186a3b394 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:14:39 -0400 Subject: [PATCH 24/27] Bring back explicit commands --- models/default-model/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/models/default-model/package.json b/models/default-model/package.json index 2037cce3f..0a04ae8e3 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -30,7 +30,10 @@ "build": "wireit", "build:cjs": "wireit", "build:esm": "wireit", - "build:umd": "wireit" + "build:umd": "wireit", + "build:umd:tsc": "wireit", + "build:umd:rollup": "wireit", + "build:umd:uglify": "wireit" }, "files": [ "assets/**/*", From c8396949852bb485784bfbf4269344d5f7821415 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:18:17 -0400 Subject: [PATCH 25/27] Fix entry points --- models/default-model/src/umd.ts | 1 + models/default-model/tsconfig.cjs.json | 2 +- models/default-model/tsconfig.esm.json | 2 +- models/default-model/tsconfig.umd.json | 2 +- packages/shared/src/esrgan/esrgan.d.ts | 12 ++ packages/shared/src/esrgan/esrgan.d.ts.map | 1 + packages/shared/src/esrgan/esrgan.js | 123 +++++++++++++++++++++ packages/shared/src/types.d.ts | 53 +++++++++ packages/shared/src/types.d.ts.map | 1 + packages/shared/src/types.js | 9 ++ 10 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 models/default-model/src/umd.ts create mode 100644 packages/shared/src/esrgan/esrgan.d.ts create mode 100644 packages/shared/src/esrgan/esrgan.d.ts.map create mode 100644 packages/shared/src/esrgan/esrgan.js create mode 100644 packages/shared/src/types.d.ts create mode 100644 packages/shared/src/types.d.ts.map create mode 100644 packages/shared/src/types.js diff --git a/models/default-model/src/umd.ts b/models/default-model/src/umd.ts new file mode 100644 index 000000000..a7f38e858 --- /dev/null +++ b/models/default-model/src/umd.ts @@ -0,0 +1 @@ +export { default as default, } from '.'; diff --git a/models/default-model/tsconfig.cjs.json b/models/default-model/tsconfig.cjs.json index f979f1b58..a5fc66d4c 100644 --- a/models/default-model/tsconfig.cjs.json +++ b/models/default-model/tsconfig.cjs.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.cjs.json", "include": [ - "./src/index.ts", + "./src/cjs.ts", ] } diff --git a/models/default-model/tsconfig.esm.json b/models/default-model/tsconfig.esm.json index 0b8c130e4..c74e5dca1 100644 --- a/models/default-model/tsconfig.esm.json +++ b/models/default-model/tsconfig.esm.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.esm.json", "include": [ - "./src/index.ts", + "./src/esm.ts", ] } diff --git a/models/default-model/tsconfig.umd.json b/models/default-model/tsconfig.umd.json index 7d7e0b242..666c3772f 100644 --- a/models/default-model/tsconfig.umd.json +++ b/models/default-model/tsconfig.umd.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.umd.json", "include": [ - "./src/index.ts", + "./src/umd.ts", ] } diff --git a/packages/shared/src/esrgan/esrgan.d.ts b/packages/shared/src/esrgan/esrgan.d.ts new file mode 100644 index 000000000..672bd02aa --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.d.ts @@ -0,0 +1,12 @@ +import type { Meta, ModelDefinition } from '../types'; +import type { Tensor4D } from '@tensorflow/tfjs-core'; +export type Inputs = Tensor4D | Tensor4D[]; +export type Scale = 2 | 3 | 4 | 8; +export declare const getESRGANModelDefinition: ({ scale, name, version, meta: { architecture, ...meta }, path: modelPath, }: { + name: string; + version: string; + scale: Scale; + meta: Meta; + path?: string | undefined; +}) => ModelDefinition; +//# sourceMappingURL=esrgan.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.d.ts.map b/packages/shared/src/esrgan/esrgan.d.ts.map new file mode 100644 index 000000000..a72efce94 --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"esrgan.d.ts","sourceRoot":"","sources":["esrgan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAS,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAG,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;AAE3C,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAclC,eAAO,MAAM,wBAAwB;UAU7B,MAAM;aACH,MAAM;WACR,KAAK;UACN,IAAI;;MAER,eAsFH,CAAC"} \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.js b/packages/shared/src/esrgan/esrgan.js new file mode 100644 index 000000000..4147c4038 --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.js @@ -0,0 +1,123 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getESRGANModelDefinition = void 0; +var isTensorArray = function (inputs) { + return Array.isArray(inputs); +}; +var getInput = function (inputs) { + if (isTensorArray(inputs)) { + return inputs[0]; + } + return inputs; +}; +var getESRGANModelDefinition = function (_a) { + var scale = _a.scale, name = _a.name, version = _a.version, _b = _a.meta, architecture = _b.architecture, meta = __rest(_b, ["architecture"]), modelPath = _a.path; + var path = modelPath || "models/".concat(scale, "x/model.json"); + if (architecture === 'rdn') { + return { + scale: scale, + modelType: 'layers', + _internals: { + path: path, + name: name, + version: version, + }, + meta: __assign({ architecture: architecture }, meta), + inputRange: [0, 255,], + outputRange: [0, 255,], + }; + } + var setup = function (tf) { + var Layer = tf.layers.Layer; + var BETA = 0.2; + var MultiplyBeta = (function (_super) { + __extends(MultiplyBeta, _super); + function MultiplyBeta() { + var _this = _super.call(this, {}) || this; + _this.beta = BETA; + return _this; + } + MultiplyBeta.prototype.call = function (inputs) { + return tf.mul(getInput(inputs), this.beta); + }; + MultiplyBeta.className = 'MultiplyBeta'; + return MultiplyBeta; + }(Layer)); + var getPixelShuffle = function (_scale) { + var PixelShuffle = (function (_super) { + __extends(PixelShuffle, _super); + function PixelShuffle() { + var _this = _super.call(this, {}) || this; + _this.scale = _scale; + return _this; + } + PixelShuffle.prototype.computeOutputShape = function (inputShape) { + return [inputShape[0], inputShape[1], inputShape[2], 3,]; + }; + PixelShuffle.prototype.call = function (inputs) { + return tf.depthToSpace(getInput(inputs), this.scale, 'NHWC'); + }; + PixelShuffle.className = "PixelShuffle".concat(scale, "x"); + return PixelShuffle; + }(Layer)); + return PixelShuffle; + }; + [ + MultiplyBeta, + getPixelShuffle(scale), + ].forEach(function (layer) { + tf.serialization.registerClass(layer); + }); + }; + return { + setup: setup, + scale: scale, + modelType: 'layers', + _internals: { + path: path, + name: name, + version: version, + }, + meta: __assign({ architecture: architecture }, meta), + inputRange: [0, 1,], + outputRange: [0, 1,], + }; +}; +exports.getESRGANModelDefinition = getESRGANModelDefinition; diff --git a/packages/shared/src/types.d.ts b/packages/shared/src/types.d.ts new file mode 100644 index 000000000..aa85f256a --- /dev/null +++ b/packages/shared/src/types.d.ts @@ -0,0 +1,53 @@ +import * as tf from '@tensorflow/tfjs-core'; +import type * as tfBrowser from '@tensorflow/tfjs'; +import type * as tfNode from '@tensorflow/tfjs-node'; +import type * as tfNodeGpu from '@tensorflow/tfjs-node-gpu'; +import { Tensor, Tensor4D } from '@tensorflow/tfjs-core'; +export type TF = typeof tfBrowser | typeof tfNode | typeof tfNodeGpu; +export type TFN = typeof tfNode | typeof tfNodeGpu; +export type OpExecutor = tfBrowser.OpExecutor | tfNode.OpExecutor | tfNodeGpu.OpExecutor; +export type GraphModel = tfBrowser.GraphModel | tfNode.GraphModel | tfNodeGpu.GraphModel; +export type ProcessFn = (t: T) => T; +export interface ModelConfigurationInternals { + name: string; + version: string; + path: string; +} +export type Range = [number, number]; +type MetaValue = string | number | Meta | null | undefined | boolean; +export type Meta = { + [key: string]: MetaValue; +}; +export type ModelType = 'graph' | 'layers'; +export type PreProcess = ProcessFn; +export type PostProcess = ProcessFn; +export type FixedShape4D = [null | number, number, number, number]; +export type DynamicShape4D = [null | number, null, null, number]; +export type Shape4D = FixedShape4D | DynamicShape4D; +export type Setup = (tf: TF) => (void | Promise); +export type Teardown = (tf: TF) => (void | Promise); +export interface ModelDefinition { + modelType?: ModelType; + path?: string; + scale?: number; + channels?: 3; + _internals?: ModelConfigurationInternals; + preprocess?: PreProcess; + postprocess?: PostProcess; + inputRange?: Range; + outputRange?: Range; + divisibilityFactor?: number; + meta?: Meta; + setup?: Setup; + teardown?: Teardown; +} +export type ModelDefinitionFn = (tf: TF) => ModelDefinition; +export type ModelDefinitionObjectOrFn = ModelDefinitionFn | ModelDefinition; +export type IsTensor = (pixels: Tensor) => pixels is T; +export declare enum MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE { + UNDEFINED = "undefined", + INVALID_MODEL_TYPE = "invalidModelType", + MISSING_PATH = "missingPath" +} +export {}; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/types.d.ts.map b/packages/shared/src/types.d.ts.map new file mode 100644 index 000000000..f3a207a3b --- /dev/null +++ b/packages/shared/src/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/packages/shared/src/types.js b/packages/shared/src/types.js new file mode 100644 index 000000000..72c0cc696 --- /dev/null +++ b/packages/shared/src/types.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = void 0; +var MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE; +(function (MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE) { + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["UNDEFINED"] = "undefined"; + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["INVALID_MODEL_TYPE"] = "invalidModelType"; + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["MISSING_PATH"] = "missingPath"; +})(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE || (exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = {})); From dedb9d865e4840a0e81c68f6dd1c1328827098f0 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:20:08 -0400 Subject: [PATCH 26/27] Change entry point in package json --- models/default-model/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/default-model/package.json b/models/default-model/package.json index 0a04ae8e3..f15eac26f 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -23,6 +23,9 @@ "import": "./dist/esm/models/default-model/src/esm.js" } }, + "module": "dist/esm/models/default-model/src/esm.js", + "types": "dist/esm/models/default-model/src/esm.d.ts", + "umd:main": "dist/umd/models/default-model/src/umd.js", "scripts": { "lint": "wireit", "prepublishOnly": "wireit", From 8b72a442591d9581d0c9a1b6f574fedeb78af3e3 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:27:53 -0400 Subject: [PATCH 27/27] Get rid of js generated files --- packages/shared/src/esrgan/esrgan.d.ts | 12 -- packages/shared/src/esrgan/esrgan.d.ts.map | 1 - packages/shared/src/esrgan/esrgan.js | 123 --------------------- packages/shared/src/types.d.ts | 53 --------- packages/shared/src/types.d.ts.map | 1 - packages/shared/src/types.js | 9 -- 6 files changed, 199 deletions(-) delete mode 100644 packages/shared/src/esrgan/esrgan.d.ts delete mode 100644 packages/shared/src/esrgan/esrgan.d.ts.map delete mode 100644 packages/shared/src/esrgan/esrgan.js delete mode 100644 packages/shared/src/types.d.ts delete mode 100644 packages/shared/src/types.d.ts.map delete mode 100644 packages/shared/src/types.js diff --git a/packages/shared/src/esrgan/esrgan.d.ts b/packages/shared/src/esrgan/esrgan.d.ts deleted file mode 100644 index 672bd02aa..000000000 --- a/packages/shared/src/esrgan/esrgan.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { Meta, ModelDefinition } from '../types'; -import type { Tensor4D } from '@tensorflow/tfjs-core'; -export type Inputs = Tensor4D | Tensor4D[]; -export type Scale = 2 | 3 | 4 | 8; -export declare const getESRGANModelDefinition: ({ scale, name, version, meta: { architecture, ...meta }, path: modelPath, }: { - name: string; - version: string; - scale: Scale; - meta: Meta; - path?: string | undefined; -}) => ModelDefinition; -//# sourceMappingURL=esrgan.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.d.ts.map b/packages/shared/src/esrgan/esrgan.d.ts.map deleted file mode 100644 index a72efce94..000000000 --- a/packages/shared/src/esrgan/esrgan.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"esrgan.d.ts","sourceRoot":"","sources":["esrgan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAS,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAG,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;AAE3C,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAclC,eAAO,MAAM,wBAAwB;UAU7B,MAAM;aACH,MAAM;WACR,KAAK;UACN,IAAI;;MAER,eAsFH,CAAC"} \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.js b/packages/shared/src/esrgan/esrgan.js deleted file mode 100644 index 4147c4038..000000000 --- a/packages/shared/src/esrgan/esrgan.js +++ /dev/null @@ -1,123 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getESRGANModelDefinition = void 0; -var isTensorArray = function (inputs) { - return Array.isArray(inputs); -}; -var getInput = function (inputs) { - if (isTensorArray(inputs)) { - return inputs[0]; - } - return inputs; -}; -var getESRGANModelDefinition = function (_a) { - var scale = _a.scale, name = _a.name, version = _a.version, _b = _a.meta, architecture = _b.architecture, meta = __rest(_b, ["architecture"]), modelPath = _a.path; - var path = modelPath || "models/".concat(scale, "x/model.json"); - if (architecture === 'rdn') { - return { - scale: scale, - modelType: 'layers', - _internals: { - path: path, - name: name, - version: version, - }, - meta: __assign({ architecture: architecture }, meta), - inputRange: [0, 255,], - outputRange: [0, 255,], - }; - } - var setup = function (tf) { - var Layer = tf.layers.Layer; - var BETA = 0.2; - var MultiplyBeta = (function (_super) { - __extends(MultiplyBeta, _super); - function MultiplyBeta() { - var _this = _super.call(this, {}) || this; - _this.beta = BETA; - return _this; - } - MultiplyBeta.prototype.call = function (inputs) { - return tf.mul(getInput(inputs), this.beta); - }; - MultiplyBeta.className = 'MultiplyBeta'; - return MultiplyBeta; - }(Layer)); - var getPixelShuffle = function (_scale) { - var PixelShuffle = (function (_super) { - __extends(PixelShuffle, _super); - function PixelShuffle() { - var _this = _super.call(this, {}) || this; - _this.scale = _scale; - return _this; - } - PixelShuffle.prototype.computeOutputShape = function (inputShape) { - return [inputShape[0], inputShape[1], inputShape[2], 3,]; - }; - PixelShuffle.prototype.call = function (inputs) { - return tf.depthToSpace(getInput(inputs), this.scale, 'NHWC'); - }; - PixelShuffle.className = "PixelShuffle".concat(scale, "x"); - return PixelShuffle; - }(Layer)); - return PixelShuffle; - }; - [ - MultiplyBeta, - getPixelShuffle(scale), - ].forEach(function (layer) { - tf.serialization.registerClass(layer); - }); - }; - return { - setup: setup, - scale: scale, - modelType: 'layers', - _internals: { - path: path, - name: name, - version: version, - }, - meta: __assign({ architecture: architecture }, meta), - inputRange: [0, 1,], - outputRange: [0, 1,], - }; -}; -exports.getESRGANModelDefinition = getESRGANModelDefinition; diff --git a/packages/shared/src/types.d.ts b/packages/shared/src/types.d.ts deleted file mode 100644 index aa85f256a..000000000 --- a/packages/shared/src/types.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -import * as tf from '@tensorflow/tfjs-core'; -import type * as tfBrowser from '@tensorflow/tfjs'; -import type * as tfNode from '@tensorflow/tfjs-node'; -import type * as tfNodeGpu from '@tensorflow/tfjs-node-gpu'; -import { Tensor, Tensor4D } from '@tensorflow/tfjs-core'; -export type TF = typeof tfBrowser | typeof tfNode | typeof tfNodeGpu; -export type TFN = typeof tfNode | typeof tfNodeGpu; -export type OpExecutor = tfBrowser.OpExecutor | tfNode.OpExecutor | tfNodeGpu.OpExecutor; -export type GraphModel = tfBrowser.GraphModel | tfNode.GraphModel | tfNodeGpu.GraphModel; -export type ProcessFn = (t: T) => T; -export interface ModelConfigurationInternals { - name: string; - version: string; - path: string; -} -export type Range = [number, number]; -type MetaValue = string | number | Meta | null | undefined | boolean; -export type Meta = { - [key: string]: MetaValue; -}; -export type ModelType = 'graph' | 'layers'; -export type PreProcess = ProcessFn; -export type PostProcess = ProcessFn; -export type FixedShape4D = [null | number, number, number, number]; -export type DynamicShape4D = [null | number, null, null, number]; -export type Shape4D = FixedShape4D | DynamicShape4D; -export type Setup = (tf: TF) => (void | Promise); -export type Teardown = (tf: TF) => (void | Promise); -export interface ModelDefinition { - modelType?: ModelType; - path?: string; - scale?: number; - channels?: 3; - _internals?: ModelConfigurationInternals; - preprocess?: PreProcess; - postprocess?: PostProcess; - inputRange?: Range; - outputRange?: Range; - divisibilityFactor?: number; - meta?: Meta; - setup?: Setup; - teardown?: Teardown; -} -export type ModelDefinitionFn = (tf: TF) => ModelDefinition; -export type ModelDefinitionObjectOrFn = ModelDefinitionFn | ModelDefinition; -export type IsTensor = (pixels: Tensor) => pixels is T; -export declare enum MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE { - UNDEFINED = "undefined", - INVALID_MODEL_TYPE = "invalidModelType", - MISSING_PATH = "missingPath" -} -export {}; -//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/types.d.ts.map b/packages/shared/src/types.d.ts.map deleted file mode 100644 index f3a207a3b..000000000 --- a/packages/shared/src/types.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/packages/shared/src/types.js b/packages/shared/src/types.js deleted file mode 100644 index 72c0cc696..000000000 --- a/packages/shared/src/types.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = void 0; -var MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE; -(function (MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE) { - MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["UNDEFINED"] = "undefined"; - MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["INVALID_MODEL_TYPE"] = "invalidModelType"; - MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["MISSING_PATH"] = "missingPath"; -})(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE || (exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = {}));