From 7aed96eac40a83bd392daa91838ed1f46e2dc9fd Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:50:00 -0500 Subject: [PATCH] Fix debug experience (#1125) --- .changeset/clever-pots-smash.md | 5 ++++ packages/browser/package.json | 2 +- packages/browser/src/browser/browser-umd.ts | 8 +++---- packages/browser/src/browser/standalone.ts | 6 ++--- packages/browser/webpack.config.js | 23 ++++++++++++++----- .../standalone-playground/package.json | 2 +- 6 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 .changeset/clever-pots-smash.md diff --git a/.changeset/clever-pots-smash.md b/.changeset/clever-pots-smash.md new file mode 100644 index 000000000..70dce21cf --- /dev/null +++ b/.changeset/clever-pots-smash.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-next': patch +--- + +Update init to allow for asset path overriding and fix debugging experience diff --git a/packages/browser/package.json b/packages/browser/package.json index 7972e82ba..a80a5d7ee 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -32,7 +32,7 @@ "tsc": "yarn run -T tsc", "jest": "yarn run -T jest", "concurrently": "yarn run -T concurrently", - "watch": "yarn concurrently 'NODE_ENV=production WATCH=true yarn umd --watch' 'yarn pkg --watch'", + "watch": "yarn concurrently 'WATCH=true yarn umd --watch' 'yarn pkg --watch'", "build": "yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'", "release:cdn": "yarn . build && NODE_ENV=production bash scripts/release.sh && NODE_ENV=stage bash scripts/release.sh", "pkg": "yarn tsc -p tsconfig.build.json", diff --git a/packages/browser/src/browser/browser-umd.ts b/packages/browser/src/browser/browser-umd.ts index d4c9b9f87..b64b7fd44 100644 --- a/packages/browser/src/browser/browser-umd.ts +++ b/packages/browser/src/browser/browser-umd.ts @@ -1,13 +1,13 @@ import { getCDN, setGlobalCDNUrl } from '../lib/parse-cdn' import { setVersionType } from '../lib/version-type' -if (process.env.ASSET_PATH) { - if (process.env.ASSET_PATH === '/dist/umd/') { +if (process.env.IS_WEBPACK_BUILD) { + if (process.env.ASSET_PATH) { // @ts-ignore - __webpack_public_path__ = '/dist/umd/' + __webpack_public_path__ = process.env.ASSET_PATH } else { const cdn = getCDN() - setGlobalCDNUrl(cdn) // preserving original behavior -- TODO: neccessary? + setGlobalCDNUrl(cdn) // @ts-ignore __webpack_public_path__ = cdn + '/analytics-next/bundles/' diff --git a/packages/browser/src/browser/standalone.ts b/packages/browser/src/browser/standalone.ts index 039653eee..86d6346de 100644 --- a/packages/browser/src/browser/standalone.ts +++ b/packages/browser/src/browser/standalone.ts @@ -2,10 +2,10 @@ import { getCDN, setGlobalCDNUrl } from '../lib/parse-cdn' import { setVersionType } from '../lib/version-type' -if (process.env.ASSET_PATH) { - if (process.env.ASSET_PATH === '/dist/umd/') { +if (process.env.IS_WEBPACK_BUILD) { + if (process.env.ASSET_PATH) { // @ts-ignore - __webpack_public_path__ = '/dist/umd/' + __webpack_public_path__ = process.env.ASSET_PATH } else { const cdn = getCDN() setGlobalCDNUrl(cdn) diff --git a/packages/browser/webpack.config.js b/packages/browser/webpack.config.js index 6733cdccb..d8ede4a9e 100644 --- a/packages/browser/webpack.config.js +++ b/packages/browser/webpack.config.js @@ -7,15 +7,26 @@ const BundleAnalyzerPlugin = const CircularDependencyPlugin = require('circular-dependency-plugin') const isProd = process.env.NODE_ENV === 'production' -const ASSET_PATH = isProd - ? 'https://cdn.segment.com/analytics-next/bundles/' - : '/dist/umd/' + +const ASSET_PATH = process.env.ASSET_PATH + ? process.env.ASSET_PATH + : !isProd + ? '/dist/umd/' + : '' + +const envPluginConfig = { + ASSET_PATH: ASSET_PATH, + IS_WEBPACK_BUILD: true, +} + +console.log('Running Webpack Build', { + NODE_ENV: process.env.NODE_ENV, + 'Webpack Environment Plugin': envPluginConfig, +}) const plugins = [ new CompressionPlugin({}), - new webpack.EnvironmentPlugin({ - ASSET_PATH, - }), + new webpack.EnvironmentPlugin(envPluginConfig), new CircularDependencyPlugin({ failOnError: true, }), diff --git a/playgrounds/standalone-playground/package.json b/playgrounds/standalone-playground/package.json index d2bce51d3..4cb22b5d5 100644 --- a/playgrounds/standalone-playground/package.json +++ b/playgrounds/standalone-playground/package.json @@ -7,7 +7,7 @@ "scripts": { ".": "yarn run -T turbo run --filter=@playground/standalone-playground...", "start": "yarn http-server . -o /pages", - "dev": "yarn concurrently 'yarn . build && yarn start' 'sleep 10 && yarn . watch'", + "dev": "yarn concurrently 'yarn start' 'sleep 3 && ASSET_PATH='/node_modules/@segment/analytics-next/dist/umd/' yarn . watch'", "concurrently": "yarn run -T concurrently" }, "dependencies": {