Skip to content

Commit 482fb35

Browse files
committed
fix: remove versionid
1 parent 0b4bb49 commit 482fb35

File tree

23 files changed

+38
-111
lines changed

23 files changed

+38
-111
lines changed

lib/build/bundlers/bundler-base.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class BundlerBase {
1111
* Represents a configuration object.
1212
* @typedef {object} BuilderConfig
1313
* @property {string} entry - The entry point for the configuration
14-
* @property {string} buildId - The build ID
1514
* @property {boolean} useNodePolyfills - Indicates if Node polyfills are being used
1615
* @property {boolean} useOwnWorker - Indicates if a custom worker is being used
1716
* @property {object} custom - Custom configuration.

lib/build/bundlers/esbuild/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class Esbuild extends BundlerBase {
1818
async run() {
1919
let config = lodash.cloneDeep(AzionEsbuildConfig);
2020
config.entryPoints = [this.builderConfig.entry];
21-
config.define = {
22-
AZION_VERSION_ID: JSON.stringify(this.builderConfig.buildId),
23-
};
21+
2422

2523
if (!config.plugins) config.plugins = [];
2624

lib/build/bundlers/esbuild/index.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('Esbuild Bundler', () => {
3838
await fs.promises.writeFile(tmpEntry.name, code);
3939

4040
const bundler = new Esbuild({
41-
buildId: '12345',
4241
custom: {},
4342
entry: tmpEntry.name,
4443
localCustom: {
@@ -65,7 +64,6 @@ describe('Esbuild Bundler', () => {
6564
'should merge the config, in this case optimization.minimize false',
6665
async () => {
6766
const bundler = new Esbuild({
68-
buildId: '12345',
6967
custom: {
7068
minify: true,
7169
},

lib/build/bundlers/webpack/index.js

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class Webpack extends BundlerBase {
2222
let config = lodash.cloneDeep(AzionWebpackConfig);
2323
config.entry = this.builderConfig.entry;
2424
config.plugins = [
25-
new webpack.DefinePlugin({
26-
AZION_VERSION_ID: JSON.stringify(this.builderConfig.buildId),
27-
}),
2825
...config.plugins,
2926
];
3027

lib/build/bundlers/webpack/index.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('Webpack Bundler', () => {
3838
await fs.promises.writeFile(tmpEntry.name, code);
3939

4040
const bundler = new Webpack({
41-
buildId: '12345',
4241
custom: {},
4342
entry: tmpEntry.name,
4443
localCustom: {
@@ -73,7 +72,6 @@ describe('Webpack Bundler', () => {
7372
'should merge the config, in this case optimization.minimize false',
7473
async () => {
7574
const bundler = new Webpack({
76-
buildId: '123456',
7775
custom: {
7876
optimization: {
7977
minimize: true,

lib/build/dispatcher/dispatcher.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ class Dispatcher {
4242
* @param {boolean} [config.useOwnWorker] - Flag indicating whether the constructed code inserts its own worker expression without the need to inject a provider.
4343
* @param {string[]|undefined} [config.memoryFS] - Reference to dirs that contains files to be injected in worker memory.
4444
* @param {object} [config.custom] - Custom Bundle configuration.
45-
* @param {string } buildId - Build ID
4645
* @param {string} vulcanLibPath - Vulcan lib absolute path
4746
*/
4847
constructor(
4948
config,
50-
buildId = generateTimestamp(),
5149
vulcanLibPath = getAbsoluteLibDirPath(),
5250
) {
5351
/* configuration */
@@ -61,7 +59,6 @@ class Dispatcher {
6159
this.memoryFS = config.memoryFS;
6260
this.custom = config.custom;
6361
/* generate */
64-
this.buildId = buildId;
6562
this.vulcanLibPath = vulcanLibPath;
6663
}
6764

@@ -255,7 +252,6 @@ class Dispatcher {
255252
* @param {object} currentConfig.memoryFS - The current memoryFS.
256253
* @param {object} config - The configuration object.
257254
* @typedef {object} BuildConfig
258-
* @property {string} buildId - Identifier for the build.
259255
* @property {boolean} useNodePolyfills - Indicates whether to use Node polyfills.
260256
* @property {boolean} useOwnWorker - Indicates whether to use a custom worker.
261257
* @property {*} localCustom - Custom configuration specific to the local environment.
@@ -265,7 +261,6 @@ class Dispatcher {
265261
*/
266262
static configureBuild(currentConfig, config) {
267263
const {
268-
buildId,
269264
useNodePolyfills,
270265
useOwnWorker,
271266
preset,
@@ -274,7 +269,6 @@ class Dispatcher {
274269
} = currentConfig;
275270
const buildConfig = { ...config };
276271

277-
buildConfig.buildId = buildId;
278272
// include config preset to priority
279273
buildConfig.useNodePolyfills =
280274
Dispatcher.checkBooleanValue(useNodePolyfills) ||
@@ -288,7 +282,7 @@ class Dispatcher {
288282
buildConfig.memoryFS = memoryFS || buildConfig?.memoryFS;
289283

290284
const currentDir = process.cwd();
291-
let tempEntryFile = `vulcan-${buildId}.temp.`;
285+
let tempEntryFile = `vulcan-${generateTimestamp()}.temp.`;
292286
tempEntryFile += preset.name === 'typescript' ? 'ts' : 'js';
293287
const tempBuilderEntryPath = join(currentDir, tempEntryFile);
294288

@@ -307,9 +301,8 @@ class Dispatcher {
307301
* @returns {Promise<object>} - A promise that resolves to an object containing the prebuild context.
308302
*/
309303
static async runPrebuild(context, buildConfig) {
310-
const { buildId, handler, prebuild } = context;
304+
const { handler, prebuild } = context;
311305
const prebuildContext = {
312-
buildId,
313306
entry: buildConfig.entry,
314307
useNodePolyfills: buildConfig.useNodePolyfills,
315308
useOwnWorker: buildConfig.useOwnWorker,
@@ -326,7 +319,7 @@ class Dispatcher {
326319
};
327320
feedback.prebuild.info(Messages.build.info.prebuild_starting);
328321
await prebuild(prebuildContext);
329-
createDotEnvFile(buildId, isWindows);
322+
createDotEnvFile(isWindows);
330323
feedback.prebuild.success(Messages.build.success.prebuild_succeeded);
331324

332325
feedback.build.info(Messages.build.info.vulcan_build_starting);
@@ -401,7 +394,6 @@ class Dispatcher {
401394

402395
const buildConfig = Dispatcher.configureBuild(
403396
{
404-
buildId: this.buildId,
405397
localCustom: this.custom,
406398
preset: this.preset,
407399
useNodePolyfills: this.useNodePolyfills,
@@ -415,7 +407,7 @@ class Dispatcher {
415407
writeFileSync(buildConfig?.entry, handler);
416408

417409
await Dispatcher.runPrebuild(
418-
{ buildId: this.buildId, handler, prebuild },
410+
{ handler, prebuild },
419411
buildConfig,
420412
);
421413
await Dispatcher.executeBuild(this.entry, this.builder, buildConfig);

lib/build/dispatcher/dispatcher.test.js

+2-36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import MockFs from 'mock-fs';
2-
import fs from 'fs';
32
import { expect } from '@jest/globals';
43
import Dispatcher from './dispatcher.js';
5-
import {
6-
createDotEnvFile,
7-
folderExistsInProject,
8-
getAliasPath,
9-
} from './helpers/helpers.js';
4+
import { folderExistsInProject, getAliasPath } from './helpers/helpers.js';
105

116
describe('dispatcher', () => {
127
const { env } = process;
@@ -41,18 +36,9 @@ describe('dispatcher', () => {
4136
useOwnWorker: false,
4237
memoryFS: undefined,
4338
custom: {},
44-
buildId: '123456',
4539
vulcanLibPath: './vulcan',
4640
};
4741

48-
/**
49-
* generate mocked timestamp
50-
* @returns {string} - timestamp
51-
*/
52-
function mockGenerateTimestamp() {
53-
return '123456';
54-
}
55-
5642
/**
5743
* mock vulcan lib absolute path
5844
* @returns {string} - absolute path
@@ -61,11 +47,7 @@ describe('dispatcher', () => {
6147
return './vulcan';
6248
}
6349

64-
const newDispatcher = new Dispatcher(
65-
config,
66-
mockGenerateTimestamp(),
67-
getAbsoluteLibDirPath(),
68-
);
50+
const newDispatcher = new Dispatcher(config, getAbsoluteLibDirPath());
6951
expect(newDispatcher).toBeInstanceOf(Dispatcher);
7052
expect(newDispatcher).toEqual(expectedDispatcher);
7153
});
@@ -88,22 +70,6 @@ describe('dispatcher', () => {
8870
MockFs.restore();
8971
});
9072

91-
it('should create dot env file', () => {
92-
MockFs({});
93-
createDotEnvFile('123456', false);
94-
const vulcanEnvContent = fs.readFileSync('/.edge/.env', 'utf8');
95-
expect(vulcanEnvContent).toEqual('VERSION_ID=123456');
96-
MockFs.restore();
97-
});
98-
99-
it('should create dot env file with windows enviroment', () => {
100-
MockFs({});
101-
createDotEnvFile('123456', true);
102-
const vulcanEnvContent = fs.readFileSync('/.edge/.env', 'utf8');
103-
expect(vulcanEnvContent).toEqual('VERSION_ID=123456');
104-
MockFs.restore();
105-
});
106-
10773
it('Should verify if one directory exist in the project', async () => {
10874
MockFs({
10975
'/dist': {},

lib/build/dispatcher/helpers/helpers.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ function getAliasPath(alias, vulcanRootPath, isWindows) {
2929

3030
/**
3131
Create a .env file in the build folder with specified parameters.
32-
* @param {string} buildId - The version ID to write into the .env file.
3332
* @param {boolean} isWindows - The boolean value indicates whether the current OS is Windows.
3433
*/
35-
function createDotEnvFile(buildId, isWindows) {
34+
function createDotEnvFile(isWindows) {
3635
const projectRoot = process.cwd();
3736
const outputPath = isWindows
3837
? fileURLToPath(new URL(`file:///${join(projectRoot, '.edge')}`))
3938
: join(projectRoot, '.edge');
4039
const envFilePath = join(outputPath, '.env');
41-
const envContent = [`VERSION_ID=${buildId}`].join('\n');
4240

4341
mkdirSync(outputPath, { recursive: true });
44-
writeFileSync(envFilePath, envContent);
42+
writeFileSync(envFilePath, '');
4543
}
4644

4745
/**

lib/env/polyfills/fetch.polyfills.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'path';
22
import { readFileSync } from 'fs';
33
import mime from 'mime-types';
44
import { EdgeRuntime } from 'edge-runtime';
5-
import { getUrlFromResource, getVulcanBuildId } from '#utils';
5+
import { getUrlFromResource } from '#utils';
66

77
/**
88
* A custom fetch implementation that adds an additional path to the URL if it starts with 'file://'.
@@ -20,8 +20,7 @@ async function fetchPolyfill(context, resource, options) {
2020
const urlObj = getUrlFromResource(context, resource);
2121

2222
if (urlObj.href.startsWith('file://')) {
23-
const versionId = getVulcanBuildId();
24-
const file = urlObj.pathname.replace(`/${versionId}`, '');
23+
const file = urlObj.pathname;
2524
const filePath = join(process.cwd(), '.edge', 'storage', file);
2625

2726
const fileContent = readFileSync(filePath);

lib/env/polyfills/fetch.polyfills.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('fetchPolyfill', () => {
2626
it('should return a response when the begin with file://', async () => {
2727
mockFS({
2828
'.edge': {
29-
'.env': 'VERSION_ID=123456',
29+
'.env': '',
3030
storage: {
3131
data: { build: { 'file.js': "console.log('ops')" } },
3232
},

lib/platform/edgehooks/mountSPA/mountSPA.hooks.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Edge } from '#namespaces';
1010
* asset or a route within the application,
1111
* and mounts the appropriate request URL for fetching the required resource from the origin server.
1212
* @param {string} requestURL - The original URL from the incoming request.
13-
* @param {string} versionId - The version ID representing the build/assets stored.
1413
* @returns {Promise<Response>} A promise that resolves to the response from the fetched resource.
1514
* @example
1615
* // Handle a request for a homepage
@@ -25,7 +24,7 @@ import { Edge } from '#namespaces';
2524
* // Input: mountSSG('https://example.com/about', 'v1');
2625
* // Output: fetch('file:///v1/index.html');
2726
*/
28-
function mountSPA(requestURL, versionId) {
27+
function mountSPA(requestURL) {
2928
/**
3029
* The path extracted from the request URL.
3130
* @type {string}
@@ -44,11 +43,11 @@ function mountSPA(requestURL, versionId) {
4443
if (fileExtensionRegex.test(requestPath)) {
4544
// If the requestPath has a file extension, it is considered an asset.
4645
// Concatenate the versionId and requestPath to form the complete asset URL.
47-
assetPath = new URL(`/${versionId}${requestPath}`, 'file://');
46+
assetPath = new URL(`${requestPath}`, 'file://');
4847
} else {
4948
// If the requestPath does not have a file extension, it is treated as a route.
5049
// Append the versionId and the route "index.html" to form the complete asset URL.
51-
assetPath = new URL(`/${versionId}/index.html`, 'file://');
50+
assetPath = new URL(`index.html`, 'file://');
5251
}
5352

5453
return fetch(assetPath);

lib/platform/edgehooks/mountSPA/mountSPA.hooks.test.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,24 @@ describe('mountSPA', () => {
1212

1313
it('should construct the assetPath for assets correctly', async () => {
1414
const requestURL = 'http://example.com/assets/image.png';
15-
const versionId = '1234567890';
1615

17-
const expectedAssetPath = new URL(
18-
`/${versionId}/assets/image.png`,
19-
'file://',
20-
);
16+
const expectedAssetPath = new URL(`assets/image.png`, 'file://');
2117

2218
global.fetch.mockResolvedValue({});
2319

24-
return mountSPA(requestURL, versionId).then(() => {
20+
return mountSPA(requestURL).then(() => {
2521
expect(global.fetch).toHaveBeenCalledWith(expectedAssetPath);
2622
});
2723
});
2824

2925
it('should construct a requestPath that does not have a file extension', async () => {
30-
const requestURL = 'http://example.com/';
31-
const versionId = '1234567890';
26+
const requestURL = 'http://example.com';
3227

33-
const expectedAssetPath = new URL(`/${versionId}/index.html`, 'file://');
28+
const expectedAssetPath = new URL(`index.html`, 'file://');
3429

3530
global.fetch.mockResolvedValue({});
3631

37-
return mountSPA(requestURL, versionId).then(() => {
32+
return mountSPA(requestURL).then(() => {
3833
expect(global.fetch).toHaveBeenCalledWith(expectedAssetPath);
3934
});
4035
});

lib/platform/edgehooks/mountSSG/mountSSG.hooks.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Edge } from '#namespaces';
99
* the appropriate asset path based on these parameters, and fetches the corresponding
1010
* response from the SSG.
1111
* @param {string} requestURL - The original URL from the event request.
12-
* @param {string} versionId - The version ID representing the build/assets stored.
1312
* @returns {Promise<Response>} A promise that resolves to the response from the SSG.
1413
* @example
1514
* // Handle a request for a homepage
@@ -24,7 +23,7 @@ import { Edge } from '#namespaces';
2423
* // Input: mountSSG('https://example.com/about', 'v1');
2524
* // Output: fetch('file:///v1/about/index.html');
2625
*/
27-
function mountSSG(requestURL, versionId) {
26+
function mountSSG(requestURL) {
2827
/**
2928
* The path extracted from the request URL.
3029
* @type {string}
@@ -48,18 +47,15 @@ function mountSSG(requestURL, versionId) {
4847

4948
if (cleanRequestPath === '/') {
5049
// If the requestPath is the root path, append the versionId and 'index.html' to the assetPath.
51-
assetPath = new URL(`/${versionId}/index.html`, 'file://');
50+
assetPath = new URL(`index.html`, 'file://');
5251
} else if (fileExtensionRegex.test(cleanRequestPath)) {
5352
// If the requestPath has a file extension, it is considered an asset.
5453
// Concatenate the versionId and requestPath to form the complete asset URL.
55-
assetPath = new URL(`/${versionId}${cleanRequestPath}`, 'file://');
54+
assetPath = new URL(`${cleanRequestPath}`, 'file://');
5655
} else {
5756
// If the requestPath is a route without a file extension,
5857
// Append the versionId and requestPath to the assetPath.
59-
assetPath = new URL(
60-
`/${versionId}${cleanRequestPath}/index.html`,
61-
'file://',
62-
);
58+
assetPath = new URL(`${cleanRequestPath}/index.html`, 'file://');
6359
}
6460

6561
return fetch(assetPath);

0 commit comments

Comments
 (0)