Skip to content

Commit

Permalink
fix: lock deps version through build
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Dec 6, 2024
1 parent 4e41fe0 commit 007f4a0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions jest/jest.setup-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global.window.document.body.innerHTML = documentHTML;
global.window.innerWidth = 1680;
global.window.innerHeight = 1024;
global.window.__BUNDLE_ALL_PLUGINS__ = false;
global.window.__LOCK_DEPS_VERSION__ = false;
global.window.__IS_LEGACY_BUILD__ = false;
global.window.__IS_DYNAMIC_CUSTOM_BUNDLE__ = false;
global.PromiseRejectionEvent = function (reason) {
Expand Down
3 changes: 2 additions & 1 deletion packages/analytics-js/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Variables required for the example
WRITE_KEY=
DATAPLANE_URL=
TEST_FILE_PATH=

# Optional variables
CONFIG_SERVER_HOST=
DEST_SDK_BASE_URL=
REMOTE_MODULES_BASE_PATH=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,14 @@ describe('Config Manager Common Utilities', () => {
['https://www.dummy.url/fromScript/v3/rsa.min.js'],
],
[undefined, ['https://www.dummy.url/fromScript/v3/other.min.js']],
[
'https://www.dummy.url/fromScript/v3/rsa.js',
['https://www.dummy.url/fromScript/v3/rsa.js'],
],
[undefined, ['https://www.dummy.url/fromScript/v3/rsa.js']],
[undefined, ['https://www.dummy.url/fromScript/v3/rudder.min.js']],
[undefined, ['https://www.dummy.url/fromScript/v3/analytics.min.js']],
[undefined, ['https://www.dummy.url/fromScript/v3/rsa.min']],
[
'https://www.dummy.url/fromScript/v3/rsa.js',
['https://www.dummy.url/fromScript/v3/rsa.js'],
],
[undefined, ['https://www.dummy.url/fromScript/v3/rsa']],
[undefined, ['https://www.dummy.url/fromScript/v3rsa.min.js']],
['/rsa.min.js', ['/rsa.min.js']],
['/rsa.js', ['/rsa.js']],
[undefined, ['/rsa.js']],
[undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js']],
[
'https://www.dummy.url/fromScript/v3/rs.min.js',
Expand All @@ -93,7 +86,7 @@ describe('Config Manager Common Utilities', () => {
[undefined, ['https://www.dummy.url/fromScript/v3/rs.min.js', 'writeKey-1']],
[undefined, ['https://www.dummy.url/fromScript/v3/rsamin.js']],
['rsa.min.js', ['rsa.min.js']],
['rsa.js', ['rsa.js']],
[undefined, ['rsa.js']],
[undefined, ['https://www.dummy.url/fromScript/v3/rsa.min.jsx']],
[undefined, [null]],
];
Expand Down
18 changes: 13 additions & 5 deletions packages/analytics-js/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
}
var loadOptions = {
logLevel: 'DEBUG',
configUrl: '__CONFIG_SERVER_HOST__',
destSDKBaseURL:
'__DEST_SDK_BASE_URL__' + window.rudderAnalyticsBuildType + '/js-integrations',
pluginsSDKBaseURL: '__PLUGINS_BASE_URL__' + window.rudderAnalyticsBuildType + '/plugins',
// integrations: {
// All: false
// },
Expand Down Expand Up @@ -168,6 +164,18 @@
// }
};

const envDestSDKBaseURL = '__DEST_SDK_BASE_URL__';
if (envDestSDKBaseURL !== 'undefined') {
loadOptions.destSDKBaseURL = envDestSDKBaseURL + window.rudderAnalyticsBuildType + '/js-integrations';
}
const envPluginsSDKBaseURL = '__PLUGINS_BASE_URL__';
if (envPluginsSDKBaseURL !== 'undefined') {
loadOptions.pluginsSDKBaseURL = envPluginsSDKBaseURL + window.rudderAnalyticsBuildType + '/plugins';
}
const envConfigUrl = '__CONFIG_SERVER_HOST__';
if (envConfigUrl !== 'undefined') {
loadOptions.configUrl = envConfigUrl;
}
rudderanalytics.load('__WRITE_KEY__', '__DATAPLANE_URL__', loadOptions);
}
}
Expand Down Expand Up @@ -391,4 +399,4 @@ <h1>Test HTML file</h1>
}
</script>
</body>
</html>
</html>
13 changes: 9 additions & 4 deletions packages/analytics-js/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ const isModuleFederatedBuild = !isDynamicCustomBuild && !isLegacyBuild;
const sourceMapType =
process.env.PROD_DEBUG === 'inline' ? 'inline' : process.env.PROD_DEBUG === 'true';
const cdnPath = isDynamicCustomBuild ? `dynamicCdnBundle` : `cdn`;
const remotePluginsBasePath =
process.env.REMOTE_MODULES_BASE_PATH || `http://localhost:3002/${cdnPath}/`;
let remotePluginsBasePath =
process.env.REMOTE_MODULES_BASE_PATH;
remotePluginsBasePath = remotePluginsBasePath?.endsWith('/') ? remotePluginsBasePath.substring(0, remotePluginsBasePath.length - 1) : remotePluginsBasePath;
let destSDKBaseURL = process.env.DEST_SDK_BASE_URL;
destSDKBaseURL = destSDKBaseURL?.endsWith('/') ? destSDKBaseURL.substring(0, destSDKBaseURL.length - 1) : destSDKBaseURL;
const outDirNpmRoot = `dist/npm`;
const outDirCDNRoot = isDynamicCustomBuild ? `dist/${cdnPath}` : `dist/${cdnPath}`;
let outDirNpm = `${outDirNpmRoot}${variantSubfolder}`;
Expand All @@ -43,6 +46,7 @@ const modName = 'rudderanalytics';
const remotePluginsExportsFilename = `rsa-plugins`;
const remotePluginsHostPromise = `Promise.resolve(window.RudderStackGlobals && window.RudderStackGlobals.app && window.RudderStackGlobals.app.pluginsCDNPath ? \`\${window.RudderStackGlobals.app.pluginsCDNPath}/${remotePluginsExportsFilename}.js\` : \`${remotePluginsBasePath}/${remotePluginsExportsFilename}.js\`)`;
const moduleType = process.env.MODULE_TYPE || 'cdn';
const lockDepsVersion = process.env.LOCK_DEPS_VERSION || 'false';
const isCDNPackageBuild = moduleType === 'cdn';
let bugsnagSDKUrl = 'https://d2wy8f7a9ursnm.cloudfront.net/v6/bugsnag.min.js';
let polyfillIoUrl = 'https://polyfill-fastly.io/v3/polyfill.min.js';
Expand Down Expand Up @@ -190,6 +194,7 @@ export function getDefaultConfig(distName) {
__IS_LEGACY_BUILD__: isLegacyBuild,
__PACKAGE_VERSION__: version,
__MODULE_TYPE__: moduleType,
__LOCK_DEPS_VERSION__: lockDepsVersion,
__SDK_BUNDLE_FILENAME__: distName,
__RS_POLYFILLIO_SDK_URL__: polyfillIoUrl,
__RS_BUGSNAG_API_KEY__: process.env.BUGSNAG_API_KEY || '{{__RS_BUGSNAG_API_KEY__}}',
Expand Down Expand Up @@ -262,8 +267,8 @@ export function getDefaultConfig(distName) {
replaceVars: {
__WRITE_KEY__: process.env.WRITE_KEY,
__DATAPLANE_URL__: process.env.DATAPLANE_URL,
__CONFIG_SERVER_HOST__: process.env.CONFIG_SERVER_HOST || '',
__DEST_SDK_BASE_URL__: process.env.DEST_SDK_BASE_URL,
__CONFIG_SERVER_HOST__: process.env.CONFIG_SERVER_HOST,
__DEST_SDK_BASE_URL__: destSDKBaseURL,
__PLUGINS_BASE_URL__: remotePluginsBasePath,
__SDK_BUNDLE_FILENAME__: distName,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const getSDKUrl = (): string | undefined => {
// TODO: We need to remove this once all the customers upgrade to the
// latest SDK loading snippet
const scripts = document.getElementsByTagName('script');
const sdkFileNameRegex = /(?:^|\/)rsa(\.min)?\.js$/;
const sdkFileNameRegex = /(?:^|\/)rsa\.min\.js$/;

// eslint-disable-next-line no-restricted-syntax
for (const script of scripts) {
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-js/src/components/utilities/loadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ const normalizeLoadOptions = (
normalizedLoadOpts.queueOptions = removeUndefinedAndNullValues(normalizedLoadOpts.queueOptions);
}

normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion !== false;
normalizedLoadOpts.lockIntegrationsVersion = normalizedLoadOpts.lockIntegrationsVersion === true;

normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion !== false;
normalizedLoadOpts.lockPluginsVersion = normalizedLoadOpts.lockPluginsVersion === true;

if (!isNumber(normalizedLoadOpts.dataPlaneEventsBufferTimeout)) {
delete normalizedLoadOpts.dataPlaneEventsBufferTimeout;
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-js/src/state/slices/loadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const defaultLoadOptions: LoadOptions = {
beaconQueueOptions: {},
destinationsQueueOptions: {},
queueOptions: {},
lockIntegrationsVersion: true,
lockPluginsVersion: true,
lockIntegrationsVersion: __LOCK_DEPS_VERSION__,
lockPluginsVersion: __LOCK_DEPS_VERSION__,
uaChTrackLevel: 'none',
plugins: [],
useGlobalIntegrationsConfigInEvents: false,
Expand Down
2 changes: 2 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ declare const __IS_DYNAMIC_CUSTOM_BUNDLE__: boolean;
declare const __IS_LEGACY_BUILD__: boolean;

declare const __BUNDLED_PLUGINS_LIST__: string | undefined;

declare const __LOCK_DEPS_VERSION__: boolean;

0 comments on commit 007f4a0

Please sign in to comment.