Skip to content

Commit

Permalink
Fix debug experience (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Aug 15, 2024
1 parent 9063d37 commit 7aed96e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-pots-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Update init to allow for asset path overriding and fix debugging experience
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/browser/browser-umd.ts
Original file line number Diff line number Diff line change
@@ -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/'
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/browser/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions packages/browser/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/standalone-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 7aed96e

Please sign in to comment.