From bc28115c11972c997077330b2b69b8109f7c7af4 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Sat, 14 Oct 2023 20:46:16 -0400 Subject: [PATCH] Update script to move bundling step into package.json (#1202) --- internals/http-server/src/HttpServer.ts | 5 +- package.json | 28 ++++++++ scripts/test.ts | 70 ++----------------- test/integration/browser.dependencies.ts | 29 -------- test/integration/clientside/tests/image.mts | 1 - test/integration/clientside/tests/model.mts | 1 - test/integration/clientside/vite.config.ts | 8 +++ test/integration/model.dependencies.ts | 13 ---- test/integration/node.dependencies.ts | 18 ----- test/integration/serverside/tests/image.mts | 4 +- .../serverside/tests/platforms.mts | 2 +- 11 files changed, 47 insertions(+), 132 deletions(-) delete mode 100644 test/integration/browser.dependencies.ts create mode 100644 test/integration/clientside/vite.config.ts delete mode 100644 test/integration/model.dependencies.ts delete mode 100644 test/integration/node.dependencies.ts diff --git a/internals/http-server/src/HttpServer.ts b/internals/http-server/src/HttpServer.ts index df9374cc6..2ed1b550b 100644 --- a/internals/http-server/src/HttpServer.ts +++ b/internals/http-server/src/HttpServer.ts @@ -1,7 +1,7 @@ import { Server as HTTPServer, createServer } from 'http'; import handler from 'serve-handler'; import { exists } from '@internals/common/fs'; -import { verbose } from '@internals/common/logger'; +import { info } from '@internals/common/logger'; import { Tunnel } from './Tunnel.js'; import { serverHeaders } from './serverHeaders.js'; @@ -73,8 +73,9 @@ export class HttpServer { this.port = getServerPort(httpServer); if (this.useTunnel) { this.tunnel = new Tunnel(this.port); - verbose('Starting server with tunnel'); + info('Starting server with tunnel'); await this.tunnel.start(); + info('Tunnel started', this.url); } const url = this.url; if (!url) { diff --git a/package.json b/package.json index 25692cbfd..b318a9755 100644 --- a/package.json +++ b/package.json @@ -253,6 +253,20 @@ "update:npm:dependencies": { "command": "pnpm --filter @upscalerjs/scripts update:npm:dependencies" }, + "bundle:webpack": { + "command": "pnpm --filter @internals/bundlers run-bundle -- webpack", + "dependencies": [ + "./packages/upscalerjs:build:browser:esm", + "build:models:esm" + ], + "files": [ + "./package.json" + ], + "output": [ + "tmp/bundlers/webpack/**/*", + "!tmp/bundlers/webpack/node_modules" + ] + }, "bundle:esbuild": { "command": "pnpm --filter @internals/bundlers run-bundle -- esbuild", "dependencies": [ @@ -309,6 +323,19 @@ "!tmp/bundlers/node/node_modules" ] }, + "bundle:umd": { + "command": "pnpm --filter @internals/bundlers run-bundle -- umd", + "dependencies": [ + "./packages/upscalerjs:build:browser:umd", + "build:models:umd" + ], + "files": [ + "./package.json" + ], + "output": [ + "tmp/bundlers/umd/**/*" + ] + }, "test:start-test-server": { "command": "ts-node test/lib/start-test-server.ts" }, @@ -380,6 +407,7 @@ "./internals/common:build", "./internals/http-server:build", "./internals/test-runner:build", + "./internals/bundlers:build", "./packages/upscalerjs:build:browser", "build:models:esm", "bundle:esbuild" diff --git a/scripts/test.ts b/scripts/test.ts index 4806836a7..98769d799 100644 --- a/scripts/test.ts +++ b/scripts/test.ts @@ -9,6 +9,7 @@ import { sync } from 'glob'; import { ifDefined as _ifDefined } from './package-scripts/prompt/ifDefined'; import { ROOT_DIR, TEST_DIR } from './package-scripts/utils/constants'; import { Bundle } from '../test/integration/utils/NodeTestRunner'; +// import { ROOT_BUNDLER_OUTPUT_DIR } from '@internals/bundlers'; const ROOT_BUNDLER_OUTPUT_DIR = path.resolve(ROOT_DIR, 'tmp/bundlers'); /**** * Types @@ -107,73 +108,16 @@ const getDependencies = async (_platforms: Platform | Platform[], runner: Runner /**** * Main function */ -const test = async (platform: Platform | Platform[], runner: Runner, kind: Kind, positionalArgs: (string | number)[], { +const test = async (platform: Platform | Platform[], runner: Runner, kind: Kind, args: (string | number)[], { verbose, - skipBundle, - skipTest, useGPU, - watch, }: { verbose?: boolean; - skipBundle?: boolean; - skipTest?: boolean; useGPU?: boolean, - watch?: boolean; }) => { - if (skipBundle !== true && !( - runner === 'browserstack' - || kind === 'memory' - || kind === 'model' - || (platform === 'node' && kind === 'integration') - || (platform === 'browser' && kind === 'integration') - )) { - const dependencies = await getDependencies(platform, runner, kind, ...positionalArgs); - const durations: number[] = []; - for (const dependency of dependencies) { - const start = performance.now(); - await dependency({ - verbose, - // skipInstallNodeModules: true, - // skipInstallLocalPackages: true, - // skipCopyFixtures: true, - }); - durations.push(performance.now() - start); - } - console.log([ - `** bundled: ${platform}`, - ...dependencies.map((fn, i) => ` - ${fn.name} in ${durations?.[i]} ms`), - ].join('\n')); - } - - if (skipTest !== true) { - const getArgs = () => { - if (runner === 'browserstack') { - throw new Error('not supported') - } - if (kind === 'model') { - return ['pnpm', 'vitest', '-c', path.resolve(ROOT_DIR, './test/integration/model/vite.config.mts')]; - } - if (kind === 'integration' && platform === 'browser') { - throw new Error('not supported') - } - if (kind === 'memory') { - throw new Error('not supported') - } - if (kind === 'integration' && platform === 'node') { - throw new Error('not supported') - } - throw new Error('Invalid') - }; - const args = getArgs().filter(Boolean).map(arg => `${arg}`); - - if (verbose) { - console.log(args.join(' ')); - } - - const code = await runTTYProcess(args[0], args.slice(1), { verbose, platform, useGPU, ROOT_BUNDLER_OUTPUT_DIR }); - if (code !== null) { - process.exit(code); - } + const code = await runTTYProcess(args[0], args.slice(1), { verbose, platform, useGPU, ROOT_BUNDLER_OUTPUT_DIR }); + if (code !== null) { + process.exit(code); } } @@ -188,9 +132,6 @@ interface Args { verbose?: boolean; kind: Kind; useGPU?: boolean; - - // this is an option only for CI; lets us separate out our build step from our test step - skipTest?: boolean; } const isValidPlatform = (platform?: string): platform is Platform => { @@ -241,7 +182,6 @@ const getArgs = async (): Promise => { const argv = await yargs(process.argv.slice(2)).options({ watch: { type: 'boolean' }, platform: { type: 'string' }, - skipTest: { type: 'boolean' }, runner: { type: 'string' }, verbose: { type: 'boolean' }, kind: { type: 'string' }, diff --git a/test/integration/browser.dependencies.ts b/test/integration/browser.dependencies.ts deleted file mode 100644 index 347d04477..000000000 --- a/test/integration/browser.dependencies.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { bundleEsbuild } from "../lib/esm-esbuild/prepare"; -import { bundleWebpack, prepareScriptBundleForESM } from "../lib/esm-webpack/prepare"; -import { prepareScriptBundleForUMD } from "../lib/umd/prepare"; - -const dependencies = { - builds: [ - prepareScriptBundleForUMD, - prepareScriptBundleForESM, - bundleWebpack, - ], - cdn: [ - bundleEsbuild, - ], - image: [ - bundleEsbuild, - ], - model: [ - bundleEsbuild, - prepareScriptBundleForUMD, - ], - speed: [ - bundleEsbuild, - ], - upscale: [ - bundleEsbuild, - ], -}; - -export default dependencies; diff --git a/test/integration/clientside/tests/image.mts b/test/integration/clientside/tests/image.mts index 70760ba28..829f98335 100644 --- a/test/integration/clientside/tests/image.mts +++ b/test/integration/clientside/tests/image.mts @@ -20,7 +20,6 @@ if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); } const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') - describe('Image Format Integration Tests', () => { const testRunner = new ClientsideTestRunner({ mock: true, diff --git a/test/integration/clientside/tests/model.mts b/test/integration/clientside/tests/model.mts index ba178ba34..5be98f9c0 100644 --- a/test/integration/clientside/tests/model.mts +++ b/test/integration/clientside/tests/model.mts @@ -18,7 +18,6 @@ if (typeof ROOT_BUNDLER_OUTPUT_DIR !== 'string') { throw new Error('ROOT_BUNDLER_OUTPUT_DIR not defined in env'); } const ESBUILD_DIST = path.resolve(ROOT_BUNDLER_OUTPUT_DIR, 'esbuild/dist') - describe('Model Loading Integration Tests', () => { const testRunner = new ClientsideTestRunner({ name: 'esm', diff --git a/test/integration/clientside/vite.config.ts b/test/integration/clientside/vite.config.ts new file mode 100644 index 000000000..5c92c704e --- /dev/null +++ b/test/integration/clientside/vite.config.ts @@ -0,0 +1,8 @@ +import { defineConfig, mergeConfig } from 'vitest/config'; +import viteConfig from '../../vite.config.mjs'; + +export default mergeConfig(viteConfig, defineConfig({ + test: { + root: __dirname, + }, +})) diff --git a/test/integration/model.dependencies.ts b/test/integration/model.dependencies.ts deleted file mode 100644 index ad2150d25..000000000 --- a/test/integration/model.dependencies.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { bundleEsbuild } from "../lib/esm-esbuild/prepare"; -import { prepareScriptBundleForNodeCJS } from "../lib/node/prepare"; -import { prepareScriptBundleForUMD } from "../lib/umd/prepare"; - -const dependencies = { - model: [ - bundleEsbuild, - prepareScriptBundleForNodeCJS, - prepareScriptBundleForUMD, - ], -}; - -export default dependencies; diff --git a/test/integration/node.dependencies.ts b/test/integration/node.dependencies.ts deleted file mode 100644 index cbc2ebc25..000000000 --- a/test/integration/node.dependencies.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { prepareScriptBundleForNodeCJS } from "../lib/node/prepare"; - -const dependencies = { - model: [ - prepareScriptBundleForNodeCJS, - ], - image: [ - prepareScriptBundleForNodeCJS, - ], - platforms: [ - prepareScriptBundleForNodeCJS, - ], - speed: [ - prepareScriptBundleForNodeCJS, - ], -}; - -export default dependencies; diff --git a/test/integration/serverside/tests/image.mts b/test/integration/serverside/tests/image.mts index 56f043825..93a377a2b 100644 --- a/test/integration/serverside/tests/image.mts +++ b/test/integration/serverside/tests/image.mts @@ -2,9 +2,9 @@ import path from 'path'; import fs from 'fs'; import { expect, describe, it, test } from 'vitest'; import * as tf from '@tensorflow/tfjs-node'; -import { checkImage } from '../../lib/utils/checkImage'; -import { MODELS_DIR } from '@internals/common/constants'; import { ServersideTestRunner } from '@internals/test-runner/serverside'; +import { checkImage } from '../../../lib/utils/checkImage.js'; +import { MODELS_DIR } from '@internals/common/constants'; import { getTemplate as _getTemplate } from '@internals/common/get-template'; const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fixtures__'); diff --git a/test/integration/serverside/tests/platforms.mts b/test/integration/serverside/tests/platforms.mts index 9203e4e27..b647a100c 100644 --- a/test/integration/serverside/tests/platforms.mts +++ b/test/integration/serverside/tests/platforms.mts @@ -1,6 +1,6 @@ import path from 'path'; import { describe, it } from 'vitest'; -import { checkImage } from '../../lib/utils/checkImage'; +import { checkImage } from '../../../lib/utils/checkImage.js'; import { MODELS_DIR } from '@internals/common/constants'; import { ServersideTestRunner } from '@internals/test-runner/serverside'; import { getTemplate } from '@internals/common/get-template';