Skip to content

Commit

Permalink
Update script to move bundling step into package.json (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott authored Oct 15, 2023
1 parent 309939e commit bc28115
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 132 deletions.
5 changes: 3 additions & 2 deletions internals/http-server/src/HttpServer.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
Expand Down
70 changes: 5 additions & 65 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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 => {
Expand Down Expand Up @@ -241,7 +182,6 @@ const getArgs = async (): Promise<Args> => {
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' },
Expand Down
29 changes: 0 additions & 29 deletions test/integration/browser.dependencies.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/clientside/tests/image.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion test/integration/clientside/tests/model.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions test/integration/clientside/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import viteConfig from '../../vite.config.mjs';

export default mergeConfig(viteConfig, defineConfig({
test: {
root: __dirname,
},
}))
13 changes: 0 additions & 13 deletions test/integration/model.dependencies.ts

This file was deleted.

18 changes: 0 additions & 18 deletions test/integration/node.dependencies.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/integration/serverside/tests/image.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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__');
Expand Down
2 changes: 1 addition & 1 deletion test/integration/serverside/tests/platforms.mts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit bc28115

Please sign in to comment.