From 70cd2656256080679ea59bdbb88b2266f03f49aa Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 4 Oct 2021 23:15:47 -0500 Subject: [PATCH] update build --- .gitignore | 7 +++- package.json | 23 ++++++++++- scripts/index.ts | 61 +++++++----------------------- scripts/utils.ts | 1 - src/integration/api-extractor.json | 2 +- src/integration/package.json | 6 +-- src/react/api-extractor.json | 2 +- src/react/package.json | 6 +-- 8 files changed, 48 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 5f24703e..a73b9b5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ .cache/ .DS_Store node_modules/ -/dist/ +/integration/ +/lib/ +/react/ /tests/~partytown/ /tests/videos/ -/tsc/ \ No newline at end of file +/tsc/ +/index.js \ No newline at end of file diff --git a/package.json b/package.json index 18f3c6f2..cbdc4313 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,27 @@ { "name": "@builder.io/partytown", - "version": "0.0.7", + "version": "0.0.8", "description": "Relocate resource intensive 3rd-party scripts off of the main thread and into a web worker.", "license": "MIT", + "main": "index.js", + "exports": { + "./integration": { + "import": "./integration/index.mjs", + "require": "./integration/index.cjs" + }, + "./react": { + "import": "./react/index.mjs", + "require": "./react/index.cjs" + }, + ".": { + "require": "./index.js" + } + }, + "files": [ + "integration/", + "lib/", + "react/" + ], "scripts": { "build": "tsc && rollup -c scripts/rollup.config.js", "build.prod": "tsc && rollup -c scripts/rollup.config.js --configApi", @@ -10,7 +29,7 @@ "dev": "tsc && concurrently \"npm:build.watch\" \"npm:tsc.watch\" -n build,tsc -c magenta,yellow", "playwright": "playwright test --browser=chromium", "playwright.webkit": "playwright test --browser=webkit", - "release": "npm run build && npm test && cd dist && np --no-2fa --no-tests ", + "release": "npm run build && npm test && np --no-2fa --no-tests", "serve": "sirv tests --port 4000 --dev", "serve.test": "sirv tests --port 5000 --dev --quiet", "test": "start-server-and-test serve.test http://localhost:5000/ playwright", diff --git a/scripts/index.ts b/scripts/index.ts index fa5e0f7a..04d15a19 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -6,7 +6,7 @@ import { buildMainSnippet } from './build-main-snippet'; import { buildIntegration } from './build-integration'; import { buildReact } from './build-react'; import { buildServiceWorker } from './build-service-worker'; -import { emptyDir, ensureDir, readJsonSync, writeFile, writeJson } from 'fs-extra'; +import { emptyDir, ensureDir, readJsonSync, writeFile } from 'fs-extra'; import { join } from 'path'; export async function runBuild(rootDir: string, isDev: boolean, generateApi: boolean) { @@ -30,11 +30,17 @@ export async function runBuild(rootDir: string, isDev: boolean, generateApi: boo async function createRootPackage(opts: BuildOptions) { if (opts.isDev) { - await ensureDir(opts.distDir); await ensureDir(opts.distTestsDir); + await ensureDir(opts.distIntegrationDir); + await ensureDir(opts.distLibDir); + await ensureDir(opts.distLibDebugDir); + await ensureDir(opts.distReactDir); } else { - await emptyDir(opts.distDir); await emptyDir(opts.distTestsDir); + await emptyDir(opts.distIntegrationDir); + await emptyDir(opts.distLibDir); + await emptyDir(opts.distLibDebugDir); + await emptyDir(opts.distReactDir); } await ensureDir(opts.distIntegrationDir); @@ -42,53 +48,15 @@ async function createRootPackage(opts: BuildOptions) { await ensureDir(opts.distLibDebugDir); await ensureDir(opts.distReactDir); - const indexJsCode = `// @builder.io/partytown`; - const indexJsPath = join(opts.distDir, 'index.js'); - await writeFile(indexJsPath, indexJsCode); - - const rootPkg = opts.packageJson; - const packageJson = { - name: rootPkg.name, - version: rootPkg.version, - description: rootPkg.description, - license: rootPkg.license, - author: rootPkg.author, - main: './index.js', - exports: { - './integration': { - import: './integration/index.mjs', - require: './integration/index.cjs', - }, - './react': { - import: './react/index.mjs', - require: './react/index.cjs', - }, - '.': { - require: './index.js', - }, - }, - files: ['./integration/', './lib/', './react/', './index.js'], - homepage: rootPkg.homepage, - keywords: rootPkg.keywords, - repository: rootPkg.repository, - publishConfig: rootPkg.publishConfig, - }; - - if (opts.isDev) { - const version = `dev.0.${Date.now()}`; - rootPkg.version = packageJson.version = version; - } - - const packageJsonPath = join(opts.distDir, 'package.json'); - await writeJson(packageJsonPath, packageJson, { spaces: 2 }); + const indexJsPath = join(opts.rootDir, 'index.js'); + await writeFile(indexJsPath, `// @builder.io/partytown\n`); } function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolean) { - const distDir = join(rootDir, 'dist'); - const distIntegrationDir = join(distDir, 'integration'); - const distLibDir = join(distDir, 'lib'); + const distIntegrationDir = join(rootDir, 'integration'); + const distLibDir = join(rootDir, 'lib'); const distLibDebugDir = join(distLibDir, 'debug'); - const distReactDir = join(distDir, 'react'); + const distReactDir = join(rootDir, 'react'); const srcDir = join(rootDir, 'src'); const srcIntegrationDir = join(srcDir, 'integration'); @@ -112,7 +80,6 @@ function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolea isDev, generateApi, rootDir, - distDir, distIntegrationDir, distLibDir, distLibDebugDir, diff --git a/scripts/utils.ts b/scripts/utils.ts index 1e005629..0e62969e 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -122,7 +122,6 @@ export interface BuildOptions { isDev: boolean; generateApi: boolean; rootDir: string; - distDir: string; distIntegrationDir: string; distLibDir: string; distLibDebugDir: string; diff --git a/src/integration/api-extractor.json b/src/integration/api-extractor.json index 6f51d348..eab712cf 100644 --- a/src/integration/api-extractor.json +++ b/src/integration/api-extractor.json @@ -13,7 +13,7 @@ }, "dtsRollup": { "enabled": true, - "untrimmedFilePath": "/dist/integration/index.d.ts" + "untrimmedFilePath": "/integration/index.d.ts" }, "docModel": { "enabled": false diff --git a/src/integration/package.json b/src/integration/package.json index 40341634..cf642ca0 100644 --- a/src/integration/package.json +++ b/src/integration/package.json @@ -1,6 +1,6 @@ { "name": "@builder.io/partytown-integration", - "main": "./index.cjs", - "module": "./index.mjs", - "types": "./index.d.ts" + "main": "index.cjs", + "module": "index.mjs", + "types": "index.d.ts" } diff --git a/src/react/api-extractor.json b/src/react/api-extractor.json index ac328bfa..84cf2241 100644 --- a/src/react/api-extractor.json +++ b/src/react/api-extractor.json @@ -13,7 +13,7 @@ }, "dtsRollup": { "enabled": true, - "untrimmedFilePath": "/dist/react/index.d.ts" + "untrimmedFilePath": "/react/index.d.ts" }, "docModel": { "enabled": false diff --git a/src/react/package.json b/src/react/package.json index db651424..2e14fd0e 100644 --- a/src/react/package.json +++ b/src/react/package.json @@ -1,6 +1,6 @@ { "name": "@builder.io/partytown-react", - "main": "./index.cjs", - "module": "./index.mjs", - "types": "./index.d.ts" + "main": "index.cjs", + "module": "index.mjs", + "types": "index.d.ts" }