Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update script library #939

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/analytics-browser/src/lib-prefix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIBPREFIX = 'amplitude-ts';
3 changes: 2 additions & 1 deletion packages/analytics-browser/src/plugins/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BeforePlugin, BrowserConfig, Event } from '@amplitude/analytics-types';
import { UUID } from '@amplitude/analytics-core';
import { getLanguage } from '@amplitude/analytics-client-common';
import { VERSION } from '../version';
import { LIBPREFIX } from '../lib-prefix';

const BROWSER_PLATFORM = 'Web';
const IP_ADDRESS = '$remote';
Expand All @@ -14,7 +15,7 @@ export class Context implements BeforePlugin {
// @ts-ignore
config: BrowserConfig;
userAgent: string | undefined;
library = `amplitude-ts/${VERSION}`;
library = `${LIBPREFIX}/${VERSION}`;

constructor() {
/* istanbul ignore else */
Expand Down
35 changes: 35 additions & 0 deletions scripts/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { terser } from 'rollup-plugin-terser';
import gzip from 'rollup-plugin-gzip';
import execute from 'rollup-plugin-execute';
import { exec } from 'child_process';
import fs from 'fs';

// The paths are relative to process.cwd(), which are packages/*
const base = '../..';
Expand Down Expand Up @@ -54,6 +55,39 @@ export const umd = {
],
};

const updateLibPrefix = (isUndo) => {
Mercy811 marked this conversation as resolved.
Show resolved Hide resolved
const path = 'src/lib-prefix.ts'
if (!fs.existsSync(path)) {
// Supported in rollup 4, we're currently rollup 2
// this.error(`File not found: ${path}`);
Mercy811 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

let content = fs.readFileSync(path, 'utf-8');
let updatedContent;
if (isUndo) {
updatedContent = content.replace(/amplitude-ts-sdk-script/g, 'amplitude-ts');
} else {
updatedContent = content.replace(/amplitude-ts/g, 'amplitude-ts-sdk-script');
}

fs.writeFileSync(path, updatedContent, 'utf-8');
// this.info(`File updated: ${path}`);
Mercy811 marked this conversation as resolved.
Show resolved Hide resolved
}


const updateLibPrefixPlugin = (isUndo) => {
Mercy811 marked this conversation as resolved.
Show resolved Hide resolved
return {
name: 'update-lib-prefix',
buildStart() {
updateLibPrefix(false);
},
buildEnd() {
updateLibPrefix(true);
}
};
}

export const iife = {
input: 'src/snippet-index.ts',
output: {
Expand All @@ -63,6 +97,7 @@ export const iife = {
sourcemap: true,
},
plugins: [
updateLibPrefixPlugin(),
Mercy811 marked this conversation as resolved.
Show resolved Hide resolved
typescript({
module: 'es6',
noEmit: false,
Expand Down
Loading