From e74eb91b14278a5d16986ffc4f47c9776567145d Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Mon, 9 Oct 2023 06:54:57 -0400 Subject: [PATCH] Clear out @upscalerjs/core directory and its references (#1189) * Clear out @upscalerjs/core directory and its references --- .deepsource.toml | 2 - internals/common/src/constants.ts | 1 - .../src/lib/package-scripts/docs/build-api.ts | 10 +- .../src/lib/package-scripts/update-version.ts | 4 +- .../lib/package-scripts/utils/constants.ts | 1 - .../src/lib/package-scripts/utils/packages.ts | 8 +- models/default-model/package.json | 1 - models/esrgan-legacy/package.json | 3 - models/esrgan-medium/package.json | 3 - models/esrgan-slim/package.json | 3 - models/esrgan-thick/package.json | 3 - models/pixel-upsampler/package.json | 3 - package.json | 1 - packages/core/.eslintrc.js | 45 ---- packages/core/.npmignore | 3 - packages/core/README.md | 4 +- packages/core/package.json | 89 +------- packages/core/src/index.test.ts | 215 ------------------ packages/core/src/index.ts | 161 ------------- packages/core/tsconfig.cjs.json | 10 - packages/core/tsconfig.eslint.json | 3 - packages/core/tsconfig.esm.json | 9 - packages/core/tsconfig.json | 25 -- packages/core/vite.conf.ts | 9 - pnpm-lock.yaml | 13 +- scripts/package-scripts/docs/build-api.ts | 13 +- scripts/package-scripts/update-version.ts | 5 +- scripts/package-scripts/utils/constants.ts | 1 - scripts/package-scripts/utils/packages.ts | 8 +- test/integration/node/model.ts | 4 +- 30 files changed, 20 insertions(+), 640 deletions(-) delete mode 100644 packages/core/.eslintrc.js delete mode 100644 packages/core/.npmignore delete mode 100644 packages/core/src/index.test.ts delete mode 100644 packages/core/src/index.ts delete mode 100644 packages/core/tsconfig.cjs.json delete mode 100644 packages/core/tsconfig.eslint.json delete mode 100644 packages/core/tsconfig.esm.json delete mode 100644 packages/core/tsconfig.json delete mode 100644 packages/core/vite.conf.ts diff --git a/.deepsource.toml b/.deepsource.toml index 76c49f189..b024fb7b7 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -3,8 +3,6 @@ version = 1 test_patterns = ["packages/upscalerjs/src/**/*.ts"] exclude_patterns = [ - "packages/core/src/**/*.test.ts", - "packages/core/jest.setup.ts", "packages/upscalerjs/src/**/*.test.ts", "packages/upscalerjs/jest.setup.ts", "examples/**", diff --git a/internals/common/src/constants.ts b/internals/common/src/constants.ts index 3ce17392c..ea1e824f0 100644 --- a/internals/common/src/constants.ts +++ b/internals/common/src/constants.ts @@ -16,7 +16,6 @@ export const DEV_DIR = path.resolve(ROOT_DIR, 'dev'); export const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages'); export const UPSCALER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs'); -export const CORE_DIR = path.resolve(PACKAGES_DIR, 'core'); export const SHARED_DIR = path.resolve(PACKAGES_DIR, 'shared'); export const WRAPPER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs-wrapper'); diff --git a/internals/upscaler-cli/src/lib/package-scripts/docs/build-api.ts b/internals/upscaler-cli/src/lib/package-scripts/docs/build-api.ts index fdfac2b66..d3b8c4dba 100644 --- a/internals/upscaler-cli/src/lib/package-scripts/docs/build-api.ts +++ b/internals/upscaler-cli/src/lib/package-scripts/docs/build-api.ts @@ -11,7 +11,7 @@ import { ReflectionKind, } from 'typedoc'; import { Platform } from '../prompt/types'; -import { CORE_DIR, DOCS_DIR, UPSCALER_DIR } from '../utils/constants'; +import { DOCS_DIR, UPSCALER_DIR } from '../utils/constants'; import { clearOutMarkdownFiles } from './utils/clear-out-markdown-files'; import { getSharedArgs, SharedArgs } from './types'; import { @@ -299,8 +299,6 @@ const writePlatformSpecificDefinitions = (definitions: Definitions): string => { */ const UPSCALER_TSCONFIG_PATH = path.resolve(UPSCALER_DIR, 'tsconfig.browser.esm.json'); const UPSCALER_SRC_PATH = path.resolve(UPSCALER_DIR, 'src/browser/esm'); -const CORE_TSCONFIG_PATH = path.resolve(CORE_DIR, 'tsconfig.json'); -const CORE_SRC_PATH = path.resolve(CORE_DIR, 'src'); const EXAMPLES_DOCS_DEST = path.resolve(DOCS_DIR, 'docs/documentation/api'); const VALID_EXPORTS_FOR_WRITING_DOCS = ['default']; const VALID_METHODS_FOR_WRITING_DOCS = [ @@ -459,18 +457,12 @@ const getDefinitions = async (): Promise => { UPSCALER_DIR, ); console.log('***** 2') - const coreTree = getPackageAsTree( - CORE_SRC_PATH, - CORE_TSCONFIG_PATH, - CORE_DIR, - ); const platformSpecificTypes = await getTypesFromPlatformSpecificFiles(); if (!upscalerTree.children) { throw new Error('No children were found on upscaler tree object. Indicates an error in the returned structure from getPackageAsTree'); } const children = [ ...upscalerTree.children, - ...(coreTree.children || []), ...(platformSpecificTypes.children || []), ]; diff --git a/internals/upscaler-cli/src/lib/package-scripts/update-version.ts b/internals/upscaler-cli/src/lib/package-scripts/update-version.ts index 07f1f4711..06e536c0f 100644 --- a/internals/upscaler-cli/src/lib/package-scripts/update-version.ts +++ b/internals/upscaler-cli/src/lib/package-scripts/update-version.ts @@ -1,6 +1,6 @@ import inquirer from 'inquirer'; import isValidVersion from './utils/isValidVersion'; -import { AVAILABLE_PACKAGES, CORE, DIRECTORIES, EXAMPLES, getPackageJSON, getPackageJSONPath, getPreparedFolderName, Package, PackageUpdaterLogger, ROOT, TransformPackageJsonFn, updateMultiplePackages, updateSinglePackage, UPSCALER_JS, WRAPPER } from './utils/packages'; +import { AVAILABLE_PACKAGES, DIRECTORIES, EXAMPLES, getPackageJSON, getPackageJSONPath, getPreparedFolderName, Package, PackageUpdaterLogger, ROOT, TransformPackageJsonFn, updateMultiplePackages, updateSinglePackage, UPSCALER_JS, WRAPPER } from './utils/packages'; import { ROOT_DIR } from './utils/constants'; /**** @@ -27,11 +27,9 @@ const getVersion = (dir: string) => { const getCurrentVersions = () => { const upscalerJSVersion = getVersion(DIRECTORIES[UPSCALER_JS].directory); const rootVersion = getVersion(DIRECTORIES[ROOT].directory); - const coreVersion = getVersion(DIRECTORIES[CORE].directory); return [ `root: ${rootVersion}`, `upscaler: ${upscalerJSVersion}`, - `core: ${coreVersion}`, ].join(' | '); }; diff --git a/internals/upscaler-cli/src/lib/package-scripts/utils/constants.ts b/internals/upscaler-cli/src/lib/package-scripts/utils/constants.ts index 722da45fb..3214d8507 100644 --- a/internals/upscaler-cli/src/lib/package-scripts/utils/constants.ts +++ b/internals/upscaler-cli/src/lib/package-scripts/utils/constants.ts @@ -17,6 +17,5 @@ export const DEV_DIR = path.resolve(ROOT_DIR, 'dev'); export const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages'); export const UPSCALER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs'); -export const CORE_DIR = path.resolve(PACKAGES_DIR, 'core'); export const SHARED_DIR = path.resolve(PACKAGES_DIR, 'shared'); export const WRAPPER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs-wrapper'); diff --git a/internals/upscaler-cli/src/lib/package-scripts/utils/packages.ts b/internals/upscaler-cli/src/lib/package-scripts/utils/packages.ts index ba5035a4d..d2a83e2d0 100644 --- a/internals/upscaler-cli/src/lib/package-scripts/utils/packages.ts +++ b/internals/upscaler-cli/src/lib/package-scripts/utils/packages.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import findAllPackages from '../find-all-packages.js'; import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; -import { CORE_DIR, DEV_DIR, DOCS_DIR, EXAMPLES_DIR, MODELS_DIR, PACKAGES_DIR, ROOT_DIR, TEST_DIR, UPSCALER_DIR, WRAPPER_DIR } from './constants.js'; +import { DEV_DIR, DOCS_DIR, EXAMPLES_DIR, MODELS_DIR, PACKAGES_DIR, ROOT_DIR, TEST_DIR, UPSCALER_DIR, WRAPPER_DIR } from './constants.js'; interface FakeExports { [index: string]: string | FakeExports; @@ -12,12 +12,11 @@ export type JSONSchema = JSONSchemaForNPMPackageJsonFiles & { exports: FakeExports; }; -export type Package = 'UpscalerJS' | 'Core' | 'Models' | 'Test' | 'Examples' | 'Root' | 'Wrapper' | 'Dev' | 'Packages'; +export type Package = 'UpscalerJS' | 'Models' | 'Test' | 'Examples' | 'Root' | 'Wrapper' | 'Dev' | 'Packages'; export type TransformPackageJsonFn = (packageJSON: JSONSchema, dir: string) => JSONSchema; export type PackageUpdaterLogger = (file: string) => (string | undefined); export const UPSCALER_JS = 'UpscalerJS'; -export const CORE = 'Core'; export const ROOT = 'Root'; export const WRAPPER = 'Wrapper'; export const EXAMPLES = 'Examples'; @@ -27,12 +26,11 @@ export const DEV = 'Development'; export const DOCS = 'Docs'; export const PACKAGES = 'Packages'; -export const AVAILABLE_PACKAGES = [ ROOT, UPSCALER_JS, CORE, MODELS, EXAMPLES, TEST, WRAPPER, DEV, DOCS, PACKAGES ]; +export const AVAILABLE_PACKAGES = [ ROOT, UPSCALER_JS, MODELS, EXAMPLES, TEST, WRAPPER, DEV, DOCS, PACKAGES ]; export const DIRECTORIES: Record = { [ROOT]: { directory: ROOT_DIR }, [UPSCALER_JS]: { directory: UPSCALER_DIR }, - [CORE]: { directory: CORE_DIR }, [MODELS]: { directory: MODELS_DIR, multiple: true }, [EXAMPLES]: { directory: EXAMPLES_DIR, multiple: true }, [TEST]: { directory: TEST_DIR, multiple: true }, diff --git a/models/default-model/package.json b/models/default-model/package.json index becbdd3b6..4ee8324b8 100644 --- a/models/default-model/package.json +++ b/models/default-model/package.json @@ -83,7 +83,6 @@ "build": { "command": "pnpm build:cjs && pnpm build:esm && pnpm build:umd", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/models/esrgan-legacy/package.json b/models/esrgan-legacy/package.json index a0de06dcf..372732839 100755 --- a/models/esrgan-legacy/package.json +++ b/models/esrgan-legacy/package.json @@ -131,7 +131,6 @@ "build:cjs": { "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -152,7 +151,6 @@ "build:esm": { "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -173,7 +171,6 @@ "build:umd": { "command": "pnpm run build:umd:tsc && pnpm run build:umd:index && pnpm run build:umd:div2k/x2 && pnpm run build:umd:div2k/x3 && pnpm run build:umd:div2k/x4 && pnpm run build:umd:psnr-small && pnpm run build:umd:gans && rimraf ./dist/umd-tmp", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/models/esrgan-medium/package.json b/models/esrgan-medium/package.json index fc3477dcc..61a45c400 100644 --- a/models/esrgan-medium/package.json +++ b/models/esrgan-medium/package.json @@ -135,7 +135,6 @@ "build:cjs": { "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -156,7 +155,6 @@ "build:esm": { "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -177,7 +175,6 @@ "build:umd": { "command": "pnpm run build:umd:tsc && pnpm run build:umd:index && pnpm run build:umd:x2 && pnpm run build:umd:x3 && pnpm run build:umd:x4 && pnpm run build:umd:x8 && rimraf ./dist/umd-tmp", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/models/esrgan-slim/package.json b/models/esrgan-slim/package.json index 28b2442c7..fd6480c88 100644 --- a/models/esrgan-slim/package.json +++ b/models/esrgan-slim/package.json @@ -135,7 +135,6 @@ "build:cjs": { "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -156,7 +155,6 @@ "build:esm": { "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -177,7 +175,6 @@ "build:umd": { "command": "pnpm run build:umd:tsc && pnpm run build:umd:index && pnpm run build:umd:x2 && pnpm run build:umd:x3 && pnpm run build:umd:x4 && pnpm run build:umd:x8 && rimraf ./dist/umd-tmp", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/models/esrgan-thick/package.json b/models/esrgan-thick/package.json index 11818284d..a6f74ed68 100644 --- a/models/esrgan-thick/package.json +++ b/models/esrgan-thick/package.json @@ -128,7 +128,6 @@ "build:cjs": { "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -149,7 +148,6 @@ "build:esm": { "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -170,7 +168,6 @@ "build:umd": { "command": "pnpm run build:umd:tsc && pnpm run build:umd:index && pnpm run build:umd:x2 && pnpm run build:umd:x3 && pnpm run build:umd:x4 && pnpm run build:umd:x8 && rimraf ./dist/umd-tmp", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/models/pixel-upsampler/package.json b/models/pixel-upsampler/package.json index d6c51e896..8f9cdc269 100644 --- a/models/pixel-upsampler/package.json +++ b/models/pixel-upsampler/package.json @@ -106,7 +106,6 @@ "build:cjs": { "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -126,7 +125,6 @@ "build:esm": { "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm --baseUrl ./src", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ @@ -146,7 +144,6 @@ "build:umd": { "command": "pnpm run build:umd:tsc && pnpm run build:umd:index && pnpm run build:umd:x2 && pnpm run build:umd:x3 && pnpm run build:umd:x4 && rimraf ./dist/umd-tmp", "dependencies": [ - "../../packages/core:build", "scaffold" ], "files": [ diff --git a/package.json b/package.json index 815a5fa16..9a259e527 100644 --- a/package.json +++ b/package.json @@ -198,7 +198,6 @@ }, "postinstall": { "dependencies": [ - "./packages/core:build", "./models/default-model:build" ] }, diff --git a/packages/core/.eslintrc.js b/packages/core/.eslintrc.js deleted file mode 100644 index b7edc8465..000000000 --- a/packages/core/.eslintrc.js +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = { - "env": { - "browser": true, - "es6": true - }, - "ignorePatterns": ["**/*.test.ts", "**/*.generated.ts"], - "extends": [ - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", - "prettier", - ], - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/semi": ["error", "always"], - "comma-dangle": ["error", "always"], - "curly": ["error", "all"], - "no-empty": [ - "error", - { - "allowEmptyCatch": true - } - ], - }, - overrides: [ - { - files: ['*.ts'], - - // As mentioned in the comments, you should extend TypeScript plugins here, - // instead of extending them outside the `overrides`. - // If you don't want to extend any rules, you don't need an `extends` attribute. - extends: [ - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/recommended-requiring-type-checking', - ], - - "parserOptions": { - "project": "./tsconfig.eslint.json", - "sourceType": "module" - }, - }, - ], -}; diff --git a/packages/core/.npmignore b/packages/core/.npmignore deleted file mode 100644 index 9ab864121..000000000 --- a/packages/core/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -*.tsbuildinfo -tmp -scaffolder.ts diff --git a/packages/core/README.md b/packages/core/README.md index 99a037180..45496513b 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -1,3 +1,3 @@ -This package is a folder of shared types and functions consumed by UpscalerJS and its upscaling models. You shouldn't install this package directly. +**DEPRECATED** -For more information on UpscalerJS, [check out the documentation](https://upscalerjs.com). +This package is deprecated. Please install `upscaler` and import types from its exports. diff --git a/packages/core/package.json b/packages/core/package.json index 8743c25ac..c87f50b00 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,90 +1,9 @@ { "name": "@upscalerjs/core", - "description": "Core library for UpscalerJS, dependency for upscaler and model packages. Not intended to be used directly.", - "version": "1.0.0-beta.15", - "main": "./dist/cjs/index.js", - "types": "./dist/cjs/index.d.ts", - "exports": { - ".": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" - } - }, + "description": "DEPRECATED: Core library for UpscalerJS, dependency for upscaler and model packages. Not intended to be used directly.", + "version": "1.0.0-beta.16", "files": [ "LICENSE", - "dist/**/*" - ], - "wireit": { - "test": { - "command": "pnpm vitest -c vite.conf.ts" - }, - "lint": { - "command": "eslint -c .eslintrc.js src --ext .ts" - }, - "prepublishOnly": { - "command": "pnpm lint && pnpm test && pnpm build && pnpm validate" - }, - "validate": { - "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", - "files": [ - "src/**/*.ts", - "!src/**/*.test.ts", - "package.json", - "vite.config.ts", - "tsconfig.esm.json", - "tsconfig.cjs.json", - "tsconfig.json" - ], - "output": [ - "dist/**" - ] - }, - "build:esm": { - "command": "tsc -p ./tsconfig.esm.json --outDir ./dist/esm", - "files": [ - "src/**/*.ts", - "!src/**/*.test.ts", - "package.json", - "vite.config.ts", - "tsconfig.esm.json", - "tsconfig.json" - ], - "output": [ - "dist/esm/**" - ] - }, - "build:cjs": { - "command": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs", - "files": [ - "src/**/*.ts", - "!src/**/*.test.ts", - "package.json", - "vite.config.ts", - "tsconfig.cjs.json", - "tsconfig.json" - ], - "output": [ - "dist/cjs/**" - ] - } - }, - "scripts": { - "test": "wireit", - "lint": "wireit", - "prepublishOnly": "wireit", - "validate": "wireit", - "build": "wireit", - "build:esm": "wireit", - "build:cjs": "wireit" - }, - "dependencies": { - "@tensorflow/tfjs-core": "~4.8.0" - }, - "devDependencies": { - "vitest": "^0.34.2", - "wireit": "^0.14.0" - } + "README" + ] } diff --git a/packages/core/src/index.test.ts b/packages/core/src/index.test.ts deleted file mode 100644 index ff103a194..000000000 --- a/packages/core/src/index.test.ts +++ /dev/null @@ -1,215 +0,0 @@ -import * as tf from '@tensorflow/tfjs-node'; -import { vi } from 'vitest'; -import { - makeIsNDimensionalTensor, - isFourDimensionalTensor, - isThreeDimensionalTensor, - isTensor, - isString, - isValidModelDefinition, - ModelDefinition, - hasValidChannels, - isValidRange, - isNumber, - isShape4D, - MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE, - isFixedShape4D, - isDynamicShape4D, -} from './index'; - -import * as tfNode from '@tensorflow/tfjs-node'; - -vi.mock('@tensorflow/tfjs', async () => { - const { ...rest } = await vi.importActual('@tensorflow/tfjs') as typeof tfNode; - return { - ...rest, - serialization: { - registerClass: vi.fn(), - }, - }; -}); - -describe('makeIsNDimensionalTensor', () => { - it('checks for a 1-dimensional tensor', () => { - const fn = makeIsNDimensionalTensor(1); - expect(fn(tf.tensor([1]))).toEqual(true); - expect(fn(tf.tensor([[1]]))).toEqual(false); - }); - - it('checks for a 2-dimensional tensor', () => { - const fn = makeIsNDimensionalTensor(2); - expect(fn(tf.tensor([1]))).toEqual(false); - expect(fn(tf.tensor([[1]]))).toEqual(true); - }); -}); - -describe('isFourDimensionalTensor', () => { - it('returns true if a 4d tensor', () => { - expect(isFourDimensionalTensor(tf.tensor([[[[1,],],],]))).toEqual(true); - }); - - it('returns false for a 3d tensor', () => { - expect(isFourDimensionalTensor(tf.tensor([[[1,],],]))).toEqual(false); - }); - - expect(isFourDimensionalTensor({} as any)).toEqual(false); -}); - -describe('isThreeDimensionalTensor', () => { - it('returns true if a 3d tensor', () => { - expect(isThreeDimensionalTensor(tf.tensor([[[1,],],]))).toEqual(true); - }); - - it('returns false for a 4d tensor', () => { - expect(isThreeDimensionalTensor(tf.tensor([[[[1,],],],]))).toEqual(false); - }); - - it('defensively handles invalid input', () => { - expect(isThreeDimensionalTensor({} as any)).toEqual(false); - }); -}); - -describe('isTensor', () => { - it('returns true if a tensor', () => { - expect(isTensor(tf.tensor([[1,],]))).toEqual(true); - }); - it('returns false if not a tensor', () => { - expect(isTensor([] as any)).toEqual(false); - }); -}); - -describe('isString', () => { - it('returns true for a string', () => { - expect(isString('foo')).toEqual(true); - }); - - it('returns false for a non-string', () => { - expect(isString({} as any)).toEqual(false); - }); -}); - -describe('isValidModelDefinition', () => { - it('throws error if given an undefined', () => { - expect(() => isValidModelDefinition(undefined)).toThrow(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.UNDEFINED); - }); - - it('throws error if given no path', () => { - expect(() => isValidModelDefinition({ path: undefined, scale: 2 } as unknown as ModelDefinition )).toThrow(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.MISSING_PATH); - }); - - it('throws error if given invalid model type', () => { - expect(() => isValidModelDefinition({ path: 'foo', scale: 2, modelType: 'foo' } as unknown as ModelDefinition )).toThrow(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.INVALID_MODEL_TYPE); - }); - - it('returns true if given scale and path', () => { - expect(isValidModelDefinition({ - path: 'foo', - scale: 2, - modelType: 'layers', - })).toEqual(true); - }); -}); - -describe('hasValidChannels', () => { - it('returns true if a tensor has valid channels', () => { - expect(hasValidChannels(tf.ones([4,4,3]))).toEqual(true); - }); - - it('returns false if a tensor does not have valid channels', () => { - expect(hasValidChannels(tf.ones([4,4,4]))).toEqual(false); - }); -}); - -describe('isNumber', () => { - it('returns true if it gets a number', () => { - expect(isNumber(1)).toEqual(true); - }); - - it('returns false if a tensor does not have valid channels', () => { - expect(isNumber('foo')).toEqual(false); - }); -}); - -describe('isValidRange', () => { - it('returns false if it gets undefined', () => { - expect(isValidRange(undefined)).toEqual(false); - }); - - it('returns false if it gets a number', () => { - expect(isValidRange(1)).toEqual(false); - }); - - it('returns false if it gets a string', () => { - expect(isValidRange('foo')).toEqual(false); - }); - - it('returns false if it gets an empty array', () => { - expect(isValidRange([])).toEqual(false); - }); - - it('returns false if it gets an array with one number', () => { - expect(isValidRange([1])).toEqual(false); - }); - - it('returns false if it gets an array with three numbers', () => { - expect(isValidRange([1,2,3])).toEqual(false); - }); - - it('returns false if it gets an array with a number and a string', () => { - expect(isValidRange([1,'foo'])).toEqual(false); - }); - - it('returns true if it gets an array with two numbers', () => { - expect(isValidRange([1,2])).toEqual(true); - }); -}); - -describe('isShape4D', () => { - it('returns false if given an undefined', () => { - expect(isShape4D(undefined)).toEqual(false); - }); - - it('returns false if given a non-array', () => { - expect(isShape4D(2)).toEqual(false); - }); - - it('returns false if given an array of 3 numbers', () => { - expect(isShape4D([1,2,3])).toEqual(false); - }); - - it('returns false if given an array of 5 numbers', () => { - expect(isShape4D([1,2,3,4,5])).toEqual(false); - }); - - it('returns false if given an array of not all numbers', () => { - expect(isShape4D([1,null,3,'foo'])).toEqual(false); - }); - - it('returns true if given an array of all numbers', () => { - expect(isShape4D([1,2,3,4])).toEqual(true); - }); - - it('returns true if given an array containing nulls', () => { - expect(isShape4D([null, null, null, 3])).toEqual(true); - }); -}); - -describe('isFixedShape4D', () => { - test.each([ - [[null, null, null, 3], false], - [[null, -1, -1, 3], false], - [[null, 2, 2, 3], true], - ])('%s | %s',(args, expectation) => { - expect(isFixedShape4D(args)).toEqual(expectation); - }); -}); - -describe('isDynamicShape', () => { - test.each([ - [[null, null, null, 3], true], - [[null, -1, -1, 3], true], - [[null, 2, 2, 3], false], - ])('%s | %s', (args, expectation) => { - expect(isDynamicShape4D(args)).toEqual(expectation); - }); -}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts deleted file mode 100644 index a0ec810a6..000000000 --- a/packages/core/src/index.ts +++ /dev/null @@ -1,161 +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, Tensor3D, Tensor4D, } from '@tensorflow/tfjs-core'; - -export type TF = typeof tfBrowser | typeof tfNode | typeof tfNodeGpu; -export type TFN = typeof tfNode | typeof tfNodeGpu; -/* eslint-disable @typescript-eslint/no-duplicate-type-constituents */ -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; - -// A model's input shape where height and width are fixed numbers -export type FixedShape4D = [null | number, number, number, number]; -// A model's input shape where height and width can be anything -export type DynamicShape4D = [null | number, null, null, number]; -export type Shape4D = FixedShape4D | DynamicShape4D; -export const isShape4D = (shape?: unknown): shape is Shape4D => { - if (!Boolean(shape) || !Array.isArray(shape) || shape.length !== 4) { - return false; - } - return shape.every((value) => value === null || typeof value === 'number'); -}; - -export const isFixedShape4D = (shape?: unknown): shape is FixedShape4D => isShape4D(shape) && shape[1] !== null && shape[2] !== null && shape[1] > 0 && shape[2] > 0; -export const isDynamicShape4D = (shape?: unknown): shape is DynamicShape4D => isShape4D(shape) && !isFixedShape4D(shape); - -export type Setup = (tf: TF) => (void | Promise); -export type Teardown = (tf: TF) => (void | Promise); - -export interface ModelDefinition { - /** - * The type of the model. Can be 'graph' or 'layer'. Defaults to 'layer'. - */ - modelType?: ModelType; - /** - * Path to a model.json file. - */ - path?: string; - /** - * The scale of the model. For super resolution models, should match the scale at which the model was trained. - */ - scale?: number; - /** - * @hidden - * - * Future option for specifying the number of channels; will enable grayscale and alpha transparency models. Current models only support 3 channels. - */ - channels?: 3; - /** - * @hidden - * - * Used internally by UpscalerJS models to encode information about the model configuration, such as package version, package name, and path to model JSON file. - */ - _internals?: ModelConfigurationInternals; - /** - * A function that processes the input image before feeding to the model. For example, you can use this function if you need to regularize your input. - */ - preprocess?: PreProcess; - /** - * A function that processes the input image after being run through model inference. For example, you may need to convert floats to 0-255 integers. - */ - postprocess?: PostProcess; - /** - * Two numbers denoting the range in which the model expects number to be in the range of. Defaults to [0, 255]. - */ - inputRange?: Range; - /** - * Two numbers denoting the range in which the model is expected to output its predictions. Numbers can still fall outside of this range, but - * UpscalerJS will use the range to clip the values appropriately. Defaults to [0, 255]. - */ - outputRange?: Range; - /** - * A number denoting whether and how an image should be divisible. For instance, a model may only operate on images that are even (divisible by 2), in - * which case this would be `2`. Only square sizes are supported for now. - */ - divisibilityFactor?: number; - /** - * @hidden - */ - meta?: Meta; - /** - * A function that runs when a model is instantiated. Can be used for registering custom layers and ops. - */ - setup?: Setup; - /** - * A function that runs when a model is disposed. Can be used for releasing memory. - */ - teardown?: Teardown; -} - -export type ModelDefinitionFn = (tf: TF) => ModelDefinition; - -export type ModelDefinitionObjectOrFn = ModelDefinitionFn | ModelDefinition; - -export type IsTensor = (pixels: Tensor) => pixels is T; -export function makeIsNDimensionalTensor(rank: number): IsTensor { - function fn(pixels: Tensor): pixels is T { - try { - return pixels.shape.length === rank; - } catch (err) { } - return false; - } - - return fn; -} -export const isFourDimensionalTensor = makeIsNDimensionalTensor(4); -export const isThreeDimensionalTensor = makeIsNDimensionalTensor(3); -export const isTensor = (input: unknown): input is tf.Tensor => input instanceof tf.Tensor; -export const isString = (el: unknown): el is string => typeof el === 'string'; - -export const isValidModelType = (modelType: unknown): modelType is ModelType => typeof modelType === 'string' && ['layers', 'graph',].includes(modelType); - -export enum MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE { - UNDEFINED = 'undefined', - INVALID_MODEL_TYPE = 'invalidModelType', - MISSING_PATH = 'missingPath', -} - -export class ModelDefinitionValidationError extends Error { - type: MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE; - - constructor(type: MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE) { - super(type); - this.type = type; - } -} - -export const isValidModelDefinition = (modelDefinition?: ModelDefinition): modelDefinition is ModelDefinition => { - if (modelDefinition === undefined) { - throw new ModelDefinitionValidationError(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.UNDEFINED); - } - if (!isValidModelType(modelDefinition.modelType ?? 'layers')) { - throw new ModelDefinitionValidationError(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.INVALID_MODEL_TYPE); - } - if (!modelDefinition.path && !modelDefinition._internals?.path) { - throw new ModelDefinitionValidationError(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE.MISSING_PATH); - } - return true; -}; - -export const hasValidChannels = (tensor: tf.Tensor): boolean => tensor.shape.slice(-1)[0] === 3; - -export const isNumber = (el: unknown): el is number => typeof el === 'number'; -export const isValidRange = (range: unknown): range is Range => Array.isArray(range) && range.length === 2 && range.every(isNumber); diff --git a/packages/core/tsconfig.cjs.json b/packages/core/tsconfig.cjs.json deleted file mode 100644 index fba994f52..000000000 --- a/packages/core/tsconfig.cjs.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS", - "moduleResolution": "Node16", - "target": "ES5", - }, - "include": ["src/index.ts", "src/cjs.ts"], - "exclude": ["node_modules", "**/*.test.ts"] -} diff --git a/packages/core/tsconfig.eslint.json b/packages/core/tsconfig.eslint.json deleted file mode 100644 index c022035ab..000000000 --- a/packages/core/tsconfig.eslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.eslint.json", -} diff --git a/packages/core/tsconfig.esm.json b/packages/core/tsconfig.esm.json deleted file mode 100644 index 5673531e4..000000000 --- a/packages/core/tsconfig.esm.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "target": "ESNext", - "module": "ESNext", - }, - "include": ["src/index.ts"], - "exclude": ["node_modules", "**/*.test.ts"] -} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json deleted file mode 100644 index 2f3b7a582..000000000 --- a/packages/core/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "esnext", - "moduleResolution": "node", - "declaration": true, - "declarationMap": true, - "outDir": "./dist", - "rootDir": "./src", - "skipLibCheck": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "composite": false, - "noUnusedLocals": true, - "esModuleInterop": true, - "strictNullChecks": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "types": [ - "vitest/globals", - ] - }, - "include": ["src/**/*.ts"], -} diff --git a/packages/core/vite.conf.ts b/packages/core/vite.conf.ts deleted file mode 100644 index c007f1378..000000000 --- a/packages/core/vite.conf.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig, } from 'vitest/config'; - -export default defineConfig({ - test: { - include: ['**/*.test.ts',], - globals: true, - }, -}); - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d39a9f951..ec3c1a3d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -854,18 +854,7 @@ importers: specifier: ^0.14.0 version: 0.14.0 - packages/core: - dependencies: - '@tensorflow/tfjs-core': - specifier: ~4.8.0 - version: 4.8.0 - devDependencies: - vitest: - specifier: ^0.34.2 - version: 0.34.2(jsdom@22.1.0) - wireit: - specifier: ^0.14.0 - version: 0.14.0 + packages/core: {} packages/shared: dependencies: diff --git a/scripts/package-scripts/docs/build-api.ts b/scripts/package-scripts/docs/build-api.ts index f6e338c41..34f969735 100644 --- a/scripts/package-scripts/docs/build-api.ts +++ b/scripts/package-scripts/docs/build-api.ts @@ -10,11 +10,10 @@ import { TypeDocReader, ReflectionKind, } from 'typedoc'; -import { runPNPMScript } from '@internals/common'; import { Platform } from '../prompt/types'; -import { CORE_DIR, DOCS_DIR, UPSCALER_DIR } from '../utils/constants'; +import { DOCS_DIR, UPSCALER_DIR } from '../utils/constants'; import { clearOutMarkdownFiles } from './utils/clear-out-markdown-files'; -import { getSharedArgs, SharedArgs } from './types'; +import { SharedArgs } from './types'; import { CommentDisplayPart, CommentTag, @@ -60,8 +59,6 @@ interface PlatformSpecificDeclarationReflection extends Omit => { UPSCALER_TSCONFIG_PATH, UPSCALER_DIR, ); - const coreTree = getPackageAsTree( - CORE_SRC_PATH, - CORE_TSCONFIG_PATH, - CORE_DIR, - ); const platformSpecificTypes = await getTypesFromPlatformSpecificFiles(); if (!upscalerTree.children) { throw new Error('No children were found on upscaler tree object. Indicates an error in the returned structure from getPackageAsTree'); } const children = [ ...upscalerTree.children, - ...(coreTree.children || []), ...(platformSpecificTypes.children || []), ]; diff --git a/scripts/package-scripts/update-version.ts b/scripts/package-scripts/update-version.ts index bf0aa6dbc..59f09a464 100644 --- a/scripts/package-scripts/update-version.ts +++ b/scripts/package-scripts/update-version.ts @@ -1,7 +1,6 @@ -import path from 'path'; import inquirer from 'inquirer'; import isValidVersion from './utils/isValidVersion'; -import { AVAILABLE_PACKAGES, CORE, DIRECTORIES, EXAMPLES, getPackageJSON, getPackageJSONPath, getPreparedFolderName, Package, PackageUpdaterLogger, ROOT, TransformPackageJsonFn, updateMultiplePackages, updateSinglePackage, UPSCALER_JS, WRAPPER } from './utils/packages'; +import { AVAILABLE_PACKAGES, DIRECTORIES, EXAMPLES, getPackageJSON, getPackageJSONPath, getPreparedFolderName, Package, PackageUpdaterLogger, ROOT, TransformPackageJsonFn, updateMultiplePackages, updateSinglePackage, UPSCALER_JS, WRAPPER } from './utils/packages'; import { ROOT_DIR } from './utils/constants'; /**** @@ -28,11 +27,9 @@ const getVersion = (dir: string) => { const getCurrentVersions = () => { const upscalerJSVersion = getVersion(DIRECTORIES[UPSCALER_JS].directory); const rootVersion = getVersion(DIRECTORIES[ROOT].directory); - const coreVersion = getVersion(DIRECTORIES[CORE].directory); return [ `root: ${rootVersion}`, `upscaler: ${upscalerJSVersion}`, - `core: ${coreVersion}`, ].join(' | '); }; diff --git a/scripts/package-scripts/utils/constants.ts b/scripts/package-scripts/utils/constants.ts index a25f6c0d3..15e184042 100644 --- a/scripts/package-scripts/utils/constants.ts +++ b/scripts/package-scripts/utils/constants.ts @@ -14,6 +14,5 @@ export const DEV_DIR = path.resolve(ROOT_DIR, 'dev'); export const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages'); export const UPSCALER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs'); -export const CORE_DIR = path.resolve(PACKAGES_DIR, 'core'); export const SHARED_DIR = path.resolve(PACKAGES_DIR, 'shared'); export const WRAPPER_DIR = path.resolve(PACKAGES_DIR, 'upscalerjs-wrapper'); diff --git a/scripts/package-scripts/utils/packages.ts b/scripts/package-scripts/utils/packages.ts index 4c09842b1..3268f141f 100644 --- a/scripts/package-scripts/utils/packages.ts +++ b/scripts/package-scripts/utils/packages.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import findAllPackages from '../find-all-packages'; import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; -import { CORE_DIR, DEV_DIR, DOCS_DIR, EXAMPLES_DIR, MODELS_DIR, PACKAGES_DIR, ROOT_DIR, TEST_DIR, UPSCALER_DIR, WRAPPER_DIR } from './constants'; +import { DEV_DIR, DOCS_DIR, EXAMPLES_DIR, MODELS_DIR, PACKAGES_DIR, ROOT_DIR, TEST_DIR, UPSCALER_DIR, WRAPPER_DIR } from './constants'; interface FakeExports { [index: string]: string | FakeExports; @@ -14,12 +14,11 @@ export type JSONSchema = JSONSchemaForNPMPackageJsonFiles & { const DIRNAME = __dirname; -export type Package = 'UpscalerJS' | 'Core' | 'Models' | 'Test' | 'Examples' | 'Root' | 'Wrapper' | 'Dev' | 'Packages'; +export type Package = 'UpscalerJS' | 'Models' | 'Test' | 'Examples' | 'Root' | 'Wrapper' | 'Dev' | 'Packages'; export type TransformPackageJsonFn = (packageJSON: JSONSchema, dir: string) => JSONSchema; export type PackageUpdaterLogger = (file: string) => (string | undefined); export const UPSCALER_JS = 'UpscalerJS'; -export const CORE = 'Core'; export const ROOT = 'Root'; export const WRAPPER = 'Wrapper'; export const EXAMPLES = 'Examples'; @@ -29,12 +28,11 @@ export const DEV = 'Development'; export const DOCS = 'Docs'; export const PACKAGES = 'Packages'; -export const AVAILABLE_PACKAGES = [ ROOT, UPSCALER_JS, CORE, MODELS, EXAMPLES, TEST, WRAPPER, DEV, DOCS, PACKAGES ]; +export const AVAILABLE_PACKAGES = [ ROOT, UPSCALER_JS, MODELS, EXAMPLES, TEST, WRAPPER, DEV, DOCS, PACKAGES ]; export const DIRECTORIES: Record = { [ROOT]: { directory: ROOT_DIR }, [UPSCALER_JS]: { directory: UPSCALER_DIR }, - [CORE]: { directory: CORE_DIR }, [MODELS]: { directory: MODELS_DIR, multiple: true }, [EXAMPLES]: { directory: EXAMPLES_DIR, multiple: true }, [TEST]: { directory: TEST_DIR, multiple: true }, diff --git a/test/integration/node/model.ts b/test/integration/node/model.ts index a4753d3ef..b5fdd9c34 100644 --- a/test/integration/node/model.ts +++ b/test/integration/node/model.ts @@ -7,9 +7,9 @@ import { MODELS_DIR, TMP_DIR } from '../../../scripts/package-scripts/utils/cons import { MultiArgTensorProgress, } from '../../../packages/upscalerjs/src/shared/types'; -import { +import type { ModelDefinition, -} from '../../../packages/core/src'; +} from '../../../packages/shared/src/types'; import { WARNING_PROGRESS_WITHOUT_PATCH_SIZE, WARNING_UNDEFINED_PADDING,