From de5c372810e6c558928d92df0da8ee76a0555018 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Tue, 6 Dec 2022 17:30:50 -0800 Subject: [PATCH 1/3] feat: bundle package deps as local packages --- src/push/bundler.ts | 89 ++++++++++++++++++++----- src/push/plugin.ts | 158 ++++++++++++++++++-------------------------- 2 files changed, 135 insertions(+), 112 deletions(-) diff --git a/src/push/bundler.ts b/src/push/bundler.ts index bb32dd7e..60c0bbff 100644 --- a/src/push/bundler.ts +++ b/src/push/bundler.ts @@ -27,23 +27,30 @@ import path from 'path'; import { stat, unlink, readFile } from 'fs/promises'; import { createWriteStream } from 'fs'; import * as esbuild from 'esbuild'; -import NodeResolve from '@esbuild-plugins/node-resolve'; import archiver from 'archiver'; -import { commonOptions, MultiAssetPlugin, PluginData } from './plugin'; +import { builtinModules } from 'module'; +import { + commonOptions, + isBare, + SyntheticsBundlePlugin, + PluginData, +} from './plugin'; const SIZE_LIMIT_KB = 800; +const BUNDLES_PATH = 'bundles'; +const EXTERNAL_MODULES = ['@elastic/synthetics']; function relativeToCwd(entry: string) { return path.relative(process.cwd(), entry); } export class Bundler { - moduleMap = new Map(); - constructor() {} + private moduleMap = new Map(); async prepare(absPath: string) { const addToMap = (data: PluginData) => { - this.moduleMap.set(data.path, data.contents); + const bundlePath = this.getModulesPath(data.path); + this.moduleMap.set(bundlePath, data.contents); }; const options: esbuild.BuildOptions = { @@ -52,19 +59,65 @@ export class Bundler { entryPoints: { [absPath]: absPath, }, - plugins: [ - MultiAssetPlugin(addToMap), - NodeResolve({ - extensions: ['.ts', '.js'], - }), - ], + plugins: [SyntheticsBundlePlugin(addToMap, EXTERNAL_MODULES)], }, }; const result = await esbuild.build(options); if (result.errors.length > 0) { throw result.errors; } - this.moduleMap.set(absPath, result.outputFiles[0].text); + } + + resolvePath(bundlePath: string) { + for (const mod of this.moduleMap.keys()) { + if (mod.startsWith(bundlePath)) { + return mod.substring(0, mod.lastIndexOf(path.extname(mod))); + } + } + return null; + } + + /** + * Rewrite the imports/requires to local node modules dependency + * to relative paths that references the bundles directory + */ + rewriteImports( + contents: string, + bundlePath: string, + external: string[] = EXTERNAL_MODULES + ) { + const packageRegex = + /s*(from|require\()\s*(['"`][^'"`]+['"`])(?=;?)(?=([^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)/gi; + + return contents.replace(packageRegex, (raw, _, dep) => { + dep = dep.replace(/['"`]/g, ''); + // Ignore rewriting for built-in modules, ignored modules and bare modules + if ( + builtinModules.includes(dep) || + external.includes(dep) || + isBare(dep) + ) { + return raw; + } + // If the module is not in node_modules, we need to go up the directory + // tree till we reach the bundles directory + let deep = bundlePath.split(path.sep).length; + let resolvedpath = this.resolvePath(BUNDLES_PATH + '/' + dep); + // If its already part of the bundles directory, we don't need to go up + if (bundlePath.startsWith(BUNDLES_PATH)) { + deep -= 1; + resolvedpath = resolvedpath.replace(BUNDLES_PATH + '/', ''); + } + return raw.replace(dep, '.'.repeat(deep) + '/' + resolvedpath); + }); + } + + getModulesPath(path: string) { + const relativePath = relativeToCwd(path); + if (relativePath.startsWith('node_modules')) { + return relativePath.replace('node_modules', BUNDLES_PATH); + } + return relativePath; } async zip(outputPath: string) { @@ -76,12 +129,12 @@ export class Bundler { archive.on('error', reject); output.on('close', fulfill); archive.pipe(output); - for (const [path, content] of this.moduleMap.entries()) { - const relativePath = relativeToCwd(path); - // Date is fixed to Unix epoch so the file metadata is - // not modified everytime when files are bundled - archive.append(content, { - name: relativePath, + for (const [path, contents] of this.moduleMap.entries()) { + // Rewrite the imports to relative paths + archive.append(this.rewriteImports(contents, path), { + name: path, + // Date is fixed to Unix epoch so the file metadata is + // not modified everytime when files are bundled date: new Date('1970-01-01'), }); } diff --git a/src/push/plugin.ts b/src/push/plugin.ts index fdf677f7..e15d04ab 100644 --- a/src/push/plugin.ts +++ b/src/push/plugin.ts @@ -23,14 +23,16 @@ * */ -import { isAbsolute, dirname, extname, join } from 'path'; -import fs from 'fs/promises'; +import { join } from 'path'; +import { readFile } from 'fs/promises'; import * as esbuild from 'esbuild'; +import NodeResolvePlugin from '@esbuild-plugins/node-resolve'; // ROOT directory of the Package - / const ROOT_DIR = join(__dirname, '..', '..'); // Source of the package - /src, /dist, etc. -const SOURCE_DIR = join(__dirname, '..'); +const SOURCE_DIR = join(ROOT_DIR, 'src'); +const DIST_DIR = join(ROOT_DIR, 'dist'); // Node modules directory of the package - /node_modules const SOURCE_NODE_MODULES = join(ROOT_DIR, 'node_modules'); @@ -44,9 +46,8 @@ export function commonOptions(): esbuild.BuildOptions { minifyWhitespace: false, treeShaking: false, keepNames: false, + logLevel: 'error', platform: 'node', - logLevel: 'silent', - format: 'esm', write: false, outExtension: { '.js': '.js', @@ -60,109 +61,78 @@ export type PluginData = { }; export type PluginCallback = (data: PluginData) => void; -export function MultiAssetPlugin(callback: PluginCallback): esbuild.Plugin { - // Check that the path isn't in an external package by making sure it's at a standard - // local filesystem location - const isBare = (str: string) => { - // Note that we use `isAbsolute` to handle UNC/windows style paths like C:\path\to\thing - // This is not necessary for relative directories since `.\file` is not supported as an import - // nor is `~/path/to/file`. - if (isAbsolute(str) || str.startsWith('./') || str.startsWith('../')) { - return true; - } - return false; - }; - - // If we're importing the @elastic/synthetics package - // directly from source instead of using the fully - // qualified name, we must skip it too. That's just - // so it doesn't get bundled on tests or when we locally - // refer to the package itself. - const isLocalSynthetics = (entryPath: string) => { - return entryPath.startsWith(SOURCE_DIR); - }; - - // When importing the local synthetics module directly - // it may import its own local dependencies, so we must - // make sure those will be resolved using Node's resolution - // algorithm, as they're still "node_modules" that we must bundle - const isLocalSyntheticsModule = (str: string) => { - return str.startsWith(SOURCE_NODE_MODULES); - }; - - return { - name: 'esbuild-multiasset-plugin', - setup(build) { - build.onResolve({ filter: /.*?/ }, async args => { - // External and other packages need be marked external to - // be removed from the bundle - if (build.initialOptions.external?.includes(args.path)) { - return { - external: true, - }; - } +// Check that the path isn't in an external package by making sure it's at a standard +// local filesystem location +export const isBare = (str: string) => { + if (str.startsWith('./') || str.startsWith('../')) { + return true; + } + return false; +}; - if ( - !isBare(args.path) || - args.importer.includes('/node_modules/') || - isLocalSyntheticsModule(args.importer) - ) { - return; - } +// Avoid importing @elastic/synthetics package from source +const isLocalSynthetics = (entryPath: string) => { + return entryPath.startsWith(SOURCE_DIR) || entryPath.startsWith(DIST_DIR); +}; - if (args.kind === 'entry-point') { - return { - path: args.path, - namespace: 'journey', - }; - } +// Avoid importing the local dependenceis of the @elastic/synthetics module +// from source +const isLocalSyntheticsModule = (str: string) => { + return str.startsWith(SOURCE_NODE_MODULES); +}; - // If the modules are resolved locally, then - // use the imported path to get full path - const entryPath = - join(dirname(args.importer), args.path) + extname(args.importer); +export function SyntheticsBundlePlugin( + callback: PluginCallback, + external: string[] +): esbuild.Plugin { + const visited = new Set(); + + return NodeResolvePlugin({ + name: 'SyntheticsBundlePlugin', + extensions: ['.ts', '.js', '.mjs'], + onNonResolved: (_, __, error) => { + throw error; + }, + onResolved: async resolved => { + if ( + external.includes(resolved) || + isLocalSynthetics(resolved) || + isLocalSyntheticsModule(resolved) + ) { + return { + external: true, + }; + } - if (isLocalSynthetics(entryPath)) { - return { external: true }; - } + if (visited.has(resolved)) { + return; + } - // Spin off another build to copy over the imported modules without bundling + // Spin off another build to copy over the imported modules without bundling + if (resolved.includes('/node_modules/')) { const result = await esbuild.build({ ...commonOptions(), - entryPoints: { - [entryPath]: entryPath, - }, + entryPoints: [resolved], bundle: false, external: [], }); callback({ - path: entryPath, + path: resolved, contents: result.outputFiles[0].text, }); - - return { - errors: result.errors, - external: true, - }; - }); - - build.onLoad({ filter: /.*?/, namespace: 'journey' }, async args => { - const contents = await fs.readFile(args.path, 'utf-8'); - callback({ path: args.path, contents }); - - // Use correct loader for the journey entry path - let loader: esbuild.Loader = 'default'; - const ext = extname(args.path).slice(1); - if (ext === 'cjs' || ext === 'mjs') { - loader = 'js'; - } else if (ext === 'cts' || ext === 'mts') { - loader = 'ts'; - } else { - loader = ext as esbuild.Loader; + } else { + // If it's a local file, read it and return the contents + // to preserve the source without modifications + try { + const contents = await readFile(resolved, 'utf-8'); + callback({ path: resolved, contents }); + } catch (e) { + throw new Error(`Could not read file ${resolved}`); } - return { contents, loader }; - }); + } + visited.add(resolved); + return; }, - }; + }); } From f252de00edb9ed0a3bfc9e07bae3ad51d032e2b1 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Wed, 7 Dec 2022 22:51:30 -0800 Subject: [PATCH 2/3] resolve and rewrite all imports --- .../push/__snapshots__/bundler.test.ts.snap | 38 ++ .../push/__snapshots__/plugin.test.ts.snap | 115 ++---- __tests__/push/bundler.test.ts | 101 +++-- __tests__/push/plugin.test.ts | 13 +- package-lock.json | 368 +++++++++--------- package.json | 2 +- src/push/bundler.ts | 45 ++- src/push/index.ts | 7 +- src/push/plugin.ts | 48 +-- src/push/utils.ts | 16 + tsconfig.json | 2 +- 11 files changed, 403 insertions(+), 352 deletions(-) create mode 100644 __tests__/push/__snapshots__/bundler.test.ts.snap diff --git a/__tests__/push/__snapshots__/bundler.test.ts.snap b/__tests__/push/__snapshots__/bundler.test.ts.snap new file mode 100644 index 00000000..6572ba37 --- /dev/null +++ b/__tests__/push/__snapshots__/bundler.test.ts.snap @@ -0,0 +1,38 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Bundler build journey 1`] = ` +" +__tests__/push/test-bundler/bundle.journey.ts +import { journey, step, monitor } from \\"@elastic/synthetics\\"; +import isPositive from \\"./bundles/is-positive/index\\"; +import utils from \\"./utils\\"; +journey(\\"journey 1\\", () => { + utils(); + monitor.use({ id: \\"duplicate id\\" }); + launchStep(-1); +}); +const launchStep = (no) => { + step(\\"step1\\", () => { + isPositive(no); + }); +}; + +__tests__/push/test-bundler/bundles/is-positive/index.js +\\"use strict\\"; +module.exports = function(n) { + return toString.call(n) === \\"[object Number]\\" && n > 0; +}; + +__tests__/push/test-bundler/utils.ts +import isNegative from \\"./bundles/is-negative/index\\"; +export default utils = () => { + isNegative(1); +}; + +__tests__/push/test-bundler/bundles/is-negative/index.js +\\"use strict\\"; +module.exports = function(n) { + return toString.call(n) === \\"[object Number]\\" && n < 0; +}; +" +`; diff --git a/__tests__/push/__snapshots__/plugin.test.ts.snap b/__tests__/push/__snapshots__/plugin.test.ts.snap index 140dc1bf..94834de3 100644 --- a/__tests__/push/__snapshots__/plugin.test.ts.snap +++ b/__tests__/push/__snapshots__/plugin.test.ts.snap @@ -1,128 +1,91 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Plugin bundle jouneys 1`] = ` -"/** - * MIT License - * - * Copyright (c) 2020-present, Elastic NV - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the \\"Software\\"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED \\"AS IS\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -import { beforeAll, journey, step } from '@elastic/synthetics'; -import axios from 'axios'; - +"import { beforeAll, journey, step } from \\"@elastic/synthetics\\"; +import axios from \\"axios\\"; beforeAll(async () => { await waitForElasticSearch(); await waitForSyntheticsData(); await waitForKibana(); }); - -journey('E2e test synthetics', async ({ page }) => { +journey(\\"E2e test synthetics\\", async ({ page }) => { async function refreshUptimeApp() { - while (!(await page.$('div.euiBasicTable'))) { - await page.click('[data-test-subj=superDatePickerApplyTimeButton]', { - timeout: 60 * 1000, + while (!await page.$(\\"div.euiBasicTable\\")) { + await page.click(\\"[data-test-subj=superDatePickerApplyTimeButton]\\", { + timeout: 60 * 1e3 }); } } - - step('Go to kibana uptime app', async () => { - await page.goto('http://localhost:5620/app/uptime', { - waitUntil: 'networkidle', + step(\\"Go to kibana uptime app\\", async () => { + await page.goto(\\"http://localhost:5620/app/uptime\\", { + waitUntil: \\"networkidle\\" }); }); - - step('Check if there is table data', async () => { - await page.click('[data-test-subj=uptimeOverviewPage]', { - timeout: 60 * 1000, + step(\\"Check if there is table data\\", async () => { + await page.click(\\"[data-test-subj=uptimeOverviewPage]\\", { + timeout: 60 * 1e3 }); await refreshUptimeApp(); - await page.click('div.euiBasicTable', { timeout: 60 * 1000 }); + await page.click(\\"div.euiBasicTable\\", { timeout: 60 * 1e3 }); }); - - step('Click on my monitor', async () => { - await page.click('[data-test-subj=monitor-page-link-my-monitor]'); + step(\\"Click on my monitor\\", async () => { + await page.click(\\"[data-test-subj=monitor-page-link-my-monitor]\\"); }); - - step('It navigates to details page', async () => { - await page.click('[data-test-subj=uptimeMonitorPage]'); + step(\\"It navigates to details page\\", async () => { + await page.click(\\"[data-test-subj=uptimeMonitorPage]\\"); }); }); - async function waitForSyntheticsData() { - console.log('Waiting for Synthetics to send data to ES for test monitor'); + console.log(\\"Waiting for Synthetics to send data to ES for test monitor\\"); let status = false; - while (!status) { try { const { data } = await axios.post( - 'http://localhost:9220/heartbeat-*/_search', + \\"http://localhost:9220/heartbeat-*/_search\\", { query: { bool: { filter: [ { term: { - 'monitor.id': 'my-monitor', - }, + \\"monitor.id\\": \\"my-monitor\\" + } }, { exists: { - field: 'summary', - }, - }, - ], - }, - }, + field: \\"summary\\" + } + } + ] + } + } } ); - - // we want some data in uptime app status = data?.hits.total.value >= 2; - } catch (e) {} + } catch (e) { + } } } - async function waitForElasticSearch() { - console.log('Waiting for Elastic Search to start'); + console.log(\\"Waiting for Elastic Search to start\\"); let esStatus = false; - while (!esStatus) { try { - const { data } = await axios.get('http://localhost:9220/_cluster/health'); - esStatus = data?.status !== 'red'; - } catch (e) {} + const { data } = await axios.get(\\"http://localhost:9220/_cluster/health\\"); + esStatus = data?.status !== \\"red\\"; + } catch (e) { + } } } - async function waitForKibana() { - console.log('Waiting for kibana server to start'); - + console.log(\\"Waiting for kibana server to start\\"); let esStatus = false; - while (!esStatus) { try { - const { data } = await axios.get('http://localhost:5620/api/status'); - esStatus = data?.status.overall.level === 'available'; - } catch (e) {} + const { data } = await axios.get(\\"http://localhost:5620/api/status\\"); + esStatus = data?.status.overall.level === \\"available\\"; + } catch (e) { + } } } " diff --git a/__tests__/push/bundler.test.ts b/__tests__/push/bundler.test.ts index 31b0836c..d7d8f050 100644 --- a/__tests__/push/bundler.test.ts +++ b/__tests__/push/bundler.test.ts @@ -27,19 +27,66 @@ import { createReadStream } from 'fs'; import { writeFile, unlink, mkdir, rm } from 'fs/promises'; import unzipper from 'unzipper'; import { join } from 'path'; +import { spawn } from 'child_process'; import { generateTempPath } from '../../src/helpers'; import { Bundler } from '../../src/push/bundler'; const PROJECT_DIR = join(__dirname, 'test-bundler'); const journeyFile = join(PROJECT_DIR, 'bundle.journey.ts'); -async function validateZip(content) { - const partialPath = join( - '__tests__', - 'push', - 'test-bundler', - 'bundle.journey.ts' +const setup = async () => { + process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = '1'; + await writeFile( + join(PROJECT_DIR, `setup.sh`), + ` + #!/bin/bash + set -e + npm init -y + npm install @elastic/synthetics is-positive is-negative + ` + ); + + await writeFile( + journeyFile, + `import {journey, step, monitor} from '@elastic/synthetics'; +import isPositive from 'is-positive'; +import isNegative from 'is-negative'; +import utils from "./utils" + +journey('journey 1', () => { + // avoid dead code elimination + utils(); + monitor.use({ id: 'duplicate id' }); + launchStep(-1); +}); + +const launchStep = (no: number) => { + step("step1", () => { + isPositive(no); + }) +};` + ); + + await writeFile( + join(PROJECT_DIR, 'utils.ts'), + `import isNegative from 'is-negative'; + export default utils = () => { + isNegative(1); + };` ); + + return new Promise(res => { + const proc = spawn('sh', ['setup.sh'], { + cwd: PROJECT_DIR, + stdio: 'pipe', + }); + proc.on('exit', code => { + res(code); + }); + }); +}; + +async function validateZip(content) { const decoded = Buffer.from(content, 'base64'); const pathToZip = generateTempPath(); await writeFile(pathToZip, decoded); @@ -53,20 +100,21 @@ async function validateZip(content) { .on('entry', function (entry) { const fileName = entry.path; files.push(fileName); - if (fileName === partialPath) { - entry.on('data', d => (targetFileContent += d)); - } else { - entry.autodrain(); - } + targetFileContent += '\n' + fileName + '\n'; + entry.on('data', d => (targetFileContent += d)); }) .on('close', r); }); - expect(files).toEqual([partialPath]); - - expect(targetFileContent).toContain('__toESM'); - expect(targetFileContent).toContain('node_modules/is-positive/index.js'); + const expectedFiles = [ + 'bundle.journey.ts', + 'bundles/is-positive/index.js', + 'utils.ts', + 'bundles/is-negative/index.js', + ].map(f => join('__tests__/push/test-bundler', f)); + expect(files).toEqual(expectedFiles); + expect(targetFileContent).toMatchSnapshot(); await unlink(pathToZip); } @@ -75,22 +123,7 @@ describe('Bundler', () => { beforeAll(async () => { await mkdir(PROJECT_DIR, { recursive: true }); - await writeFile( - journeyFile, - `import {journey, step, monitor} from '@elastic/synthetics'; -import isPositive from 'is-positive'; - -journey('journey 1', () => { - monitor.use({ id: 'duplicate id' }); - launchStep(-1); -}); - -const launchStep = (no: number) => { - step("step1", () => { - isPositive(no); - }) -};` - ); + await setup(); }); afterAll(async () => { @@ -100,7 +133,7 @@ const launchStep = (no: number) => { it('build journey', async () => { const content = await bundler.build(journeyFile, generateTempPath()); await validateZip(content); - }); + }, 15000); it('bundle should be idempotent', async () => { const content1 = await bundler.build(journeyFile, generateTempPath()); @@ -112,7 +145,9 @@ const launchStep = (no: number) => { try { await bundler.build(join(PROJECT_DIR, 'blah.ts'), generateTempPath()); } catch (e) { - expect(e.message).toContain('ENOENT'); + expect(e.message).toContain( + '[plugin: SyntheticsBundlePlugin] Cannot find module' + ); } }); }); diff --git a/__tests__/push/plugin.test.ts b/__tests__/push/plugin.test.ts index f11ee670..1d6c795b 100644 --- a/__tests__/push/plugin.test.ts +++ b/__tests__/push/plugin.test.ts @@ -25,9 +25,8 @@ import * as esbuild from 'esbuild'; import { join } from 'path'; -import NodeResolve from '@esbuild-plugins/node-resolve'; import { - MultiAssetPlugin, + SyntheticsBundlePlugin, commonOptions, PluginData, } from '../../src/push/plugin'; @@ -43,14 +42,10 @@ describe('Plugin', () => { await esbuild.build({ ...commonOptions(), + bundle: false, + external: [], entryPoints: [join(E2E_DIR, 'uptime.journey.ts')], - plugins: [ - MultiAssetPlugin(callback), - NodeResolve({ - extensions: ['.ts', '.js'], - resolveOptions: { basedir: E2E_DIR }, - }), - ], + plugins: [SyntheticsBundlePlugin(callback)], }); }); }); diff --git a/package-lock.json b/package-lock.json index 3abe5a1c..0dfc7bb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "commander": "^9.4.1", "deepmerge": "^4.2.2", "enquirer": "^2.3.6", - "esbuild": "^0.15.13", + "esbuild": "^0.15.18", "expect": "^28.1.3", "http-proxy": "^1.18.1", "kleur": "^4.1.5", @@ -675,9 +675,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.13.tgz", - "integrity": "sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.18.tgz", + "integrity": "sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==", "cpu": [ "arm" ], @@ -690,9 +690,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.13.tgz", - "integrity": "sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.18.tgz", + "integrity": "sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==", "cpu": [ "loong64" ], @@ -2688,9 +2688,9 @@ } }, "node_modules/esbuild": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.13.tgz", - "integrity": "sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.18.tgz", + "integrity": "sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==", "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" @@ -2699,34 +2699,34 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.15.13", - "@esbuild/linux-loong64": "0.15.13", - "esbuild-android-64": "0.15.13", - "esbuild-android-arm64": "0.15.13", - "esbuild-darwin-64": "0.15.13", - "esbuild-darwin-arm64": "0.15.13", - "esbuild-freebsd-64": "0.15.13", - "esbuild-freebsd-arm64": "0.15.13", - "esbuild-linux-32": "0.15.13", - "esbuild-linux-64": "0.15.13", - "esbuild-linux-arm": "0.15.13", - "esbuild-linux-arm64": "0.15.13", - "esbuild-linux-mips64le": "0.15.13", - "esbuild-linux-ppc64le": "0.15.13", - "esbuild-linux-riscv64": "0.15.13", - "esbuild-linux-s390x": "0.15.13", - "esbuild-netbsd-64": "0.15.13", - "esbuild-openbsd-64": "0.15.13", - "esbuild-sunos-64": "0.15.13", - "esbuild-windows-32": "0.15.13", - "esbuild-windows-64": "0.15.13", - "esbuild-windows-arm64": "0.15.13" + "@esbuild/android-arm": "0.15.18", + "@esbuild/linux-loong64": "0.15.18", + "esbuild-android-64": "0.15.18", + "esbuild-android-arm64": "0.15.18", + "esbuild-darwin-64": "0.15.18", + "esbuild-darwin-arm64": "0.15.18", + "esbuild-freebsd-64": "0.15.18", + "esbuild-freebsd-arm64": "0.15.18", + "esbuild-linux-32": "0.15.18", + "esbuild-linux-64": "0.15.18", + "esbuild-linux-arm": "0.15.18", + "esbuild-linux-arm64": "0.15.18", + "esbuild-linux-mips64le": "0.15.18", + "esbuild-linux-ppc64le": "0.15.18", + "esbuild-linux-riscv64": "0.15.18", + "esbuild-linux-s390x": "0.15.18", + "esbuild-netbsd-64": "0.15.18", + "esbuild-openbsd-64": "0.15.18", + "esbuild-sunos-64": "0.15.18", + "esbuild-windows-32": "0.15.18", + "esbuild-windows-64": "0.15.18", + "esbuild-windows-arm64": "0.15.18" } }, "node_modules/esbuild-android-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.13.tgz", - "integrity": "sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.18.tgz", + "integrity": "sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==", "cpu": [ "x64" ], @@ -2739,9 +2739,9 @@ } }, "node_modules/esbuild-android-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.13.tgz", - "integrity": "sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.18.tgz", + "integrity": "sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==", "cpu": [ "arm64" ], @@ -2754,9 +2754,9 @@ } }, "node_modules/esbuild-darwin-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.13.tgz", - "integrity": "sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.18.tgz", + "integrity": "sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==", "cpu": [ "x64" ], @@ -2769,9 +2769,9 @@ } }, "node_modules/esbuild-darwin-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.13.tgz", - "integrity": "sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.18.tgz", + "integrity": "sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==", "cpu": [ "arm64" ], @@ -2784,9 +2784,9 @@ } }, "node_modules/esbuild-freebsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.13.tgz", - "integrity": "sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.18.tgz", + "integrity": "sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==", "cpu": [ "x64" ], @@ -2799,9 +2799,9 @@ } }, "node_modules/esbuild-freebsd-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.13.tgz", - "integrity": "sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.18.tgz", + "integrity": "sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==", "cpu": [ "arm64" ], @@ -2814,9 +2814,9 @@ } }, "node_modules/esbuild-linux-32": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.13.tgz", - "integrity": "sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.18.tgz", + "integrity": "sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==", "cpu": [ "ia32" ], @@ -2829,9 +2829,9 @@ } }, "node_modules/esbuild-linux-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.13.tgz", - "integrity": "sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.18.tgz", + "integrity": "sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==", "cpu": [ "x64" ], @@ -2844,9 +2844,9 @@ } }, "node_modules/esbuild-linux-arm": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.13.tgz", - "integrity": "sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.18.tgz", + "integrity": "sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==", "cpu": [ "arm" ], @@ -2859,9 +2859,9 @@ } }, "node_modules/esbuild-linux-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.13.tgz", - "integrity": "sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.18.tgz", + "integrity": "sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==", "cpu": [ "arm64" ], @@ -2874,9 +2874,9 @@ } }, "node_modules/esbuild-linux-mips64le": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.13.tgz", - "integrity": "sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.18.tgz", + "integrity": "sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==", "cpu": [ "mips64el" ], @@ -2889,9 +2889,9 @@ } }, "node_modules/esbuild-linux-ppc64le": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.13.tgz", - "integrity": "sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.18.tgz", + "integrity": "sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==", "cpu": [ "ppc64" ], @@ -2904,9 +2904,9 @@ } }, "node_modules/esbuild-linux-riscv64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.13.tgz", - "integrity": "sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.18.tgz", + "integrity": "sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==", "cpu": [ "riscv64" ], @@ -2919,9 +2919,9 @@ } }, "node_modules/esbuild-linux-s390x": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.13.tgz", - "integrity": "sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.18.tgz", + "integrity": "sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==", "cpu": [ "s390x" ], @@ -2934,9 +2934,9 @@ } }, "node_modules/esbuild-netbsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.13.tgz", - "integrity": "sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.18.tgz", + "integrity": "sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==", "cpu": [ "x64" ], @@ -2949,9 +2949,9 @@ } }, "node_modules/esbuild-openbsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.13.tgz", - "integrity": "sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.18.tgz", + "integrity": "sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==", "cpu": [ "x64" ], @@ -2964,9 +2964,9 @@ } }, "node_modules/esbuild-sunos-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.13.tgz", - "integrity": "sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.18.tgz", + "integrity": "sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==", "cpu": [ "x64" ], @@ -2979,9 +2979,9 @@ } }, "node_modules/esbuild-windows-32": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.13.tgz", - "integrity": "sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.18.tgz", + "integrity": "sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==", "cpu": [ "ia32" ], @@ -2994,9 +2994,9 @@ } }, "node_modules/esbuild-windows-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.13.tgz", - "integrity": "sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.18.tgz", + "integrity": "sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==", "cpu": [ "x64" ], @@ -3009,9 +3009,9 @@ } }, "node_modules/esbuild-windows-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.13.tgz", - "integrity": "sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.18.tgz", + "integrity": "sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==", "cpu": [ "arm64" ], @@ -7275,15 +7275,15 @@ } }, "@esbuild/android-arm": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.13.tgz", - "integrity": "sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.18.tgz", + "integrity": "sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==", "optional": true }, "@esbuild/linux-loong64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.13.tgz", - "integrity": "sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.18.tgz", + "integrity": "sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==", "optional": true }, "@eslint/eslintrc": { @@ -8788,152 +8788,152 @@ } }, "esbuild": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.13.tgz", - "integrity": "sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==", - "requires": { - "@esbuild/android-arm": "0.15.13", - "@esbuild/linux-loong64": "0.15.13", - "esbuild-android-64": "0.15.13", - "esbuild-android-arm64": "0.15.13", - "esbuild-darwin-64": "0.15.13", - "esbuild-darwin-arm64": "0.15.13", - "esbuild-freebsd-64": "0.15.13", - "esbuild-freebsd-arm64": "0.15.13", - "esbuild-linux-32": "0.15.13", - "esbuild-linux-64": "0.15.13", - "esbuild-linux-arm": "0.15.13", - "esbuild-linux-arm64": "0.15.13", - "esbuild-linux-mips64le": "0.15.13", - "esbuild-linux-ppc64le": "0.15.13", - "esbuild-linux-riscv64": "0.15.13", - "esbuild-linux-s390x": "0.15.13", - "esbuild-netbsd-64": "0.15.13", - "esbuild-openbsd-64": "0.15.13", - "esbuild-sunos-64": "0.15.13", - "esbuild-windows-32": "0.15.13", - "esbuild-windows-64": "0.15.13", - "esbuild-windows-arm64": "0.15.13" + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.18.tgz", + "integrity": "sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==", + "requires": { + "@esbuild/android-arm": "0.15.18", + "@esbuild/linux-loong64": "0.15.18", + "esbuild-android-64": "0.15.18", + "esbuild-android-arm64": "0.15.18", + "esbuild-darwin-64": "0.15.18", + "esbuild-darwin-arm64": "0.15.18", + "esbuild-freebsd-64": "0.15.18", + "esbuild-freebsd-arm64": "0.15.18", + "esbuild-linux-32": "0.15.18", + "esbuild-linux-64": "0.15.18", + "esbuild-linux-arm": "0.15.18", + "esbuild-linux-arm64": "0.15.18", + "esbuild-linux-mips64le": "0.15.18", + "esbuild-linux-ppc64le": "0.15.18", + "esbuild-linux-riscv64": "0.15.18", + "esbuild-linux-s390x": "0.15.18", + "esbuild-netbsd-64": "0.15.18", + "esbuild-openbsd-64": "0.15.18", + "esbuild-sunos-64": "0.15.18", + "esbuild-windows-32": "0.15.18", + "esbuild-windows-64": "0.15.18", + "esbuild-windows-arm64": "0.15.18" } }, "esbuild-android-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.13.tgz", - "integrity": "sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.18.tgz", + "integrity": "sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==", "optional": true }, "esbuild-android-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.13.tgz", - "integrity": "sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.18.tgz", + "integrity": "sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==", "optional": true }, "esbuild-darwin-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.13.tgz", - "integrity": "sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.18.tgz", + "integrity": "sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==", "optional": true }, "esbuild-darwin-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.13.tgz", - "integrity": "sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.18.tgz", + "integrity": "sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==", "optional": true }, "esbuild-freebsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.13.tgz", - "integrity": "sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.18.tgz", + "integrity": "sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==", "optional": true }, "esbuild-freebsd-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.13.tgz", - "integrity": "sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.18.tgz", + "integrity": "sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==", "optional": true }, "esbuild-linux-32": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.13.tgz", - "integrity": "sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.18.tgz", + "integrity": "sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==", "optional": true }, "esbuild-linux-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.13.tgz", - "integrity": "sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.18.tgz", + "integrity": "sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==", "optional": true }, "esbuild-linux-arm": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.13.tgz", - "integrity": "sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.18.tgz", + "integrity": "sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==", "optional": true }, "esbuild-linux-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.13.tgz", - "integrity": "sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.18.tgz", + "integrity": "sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==", "optional": true }, "esbuild-linux-mips64le": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.13.tgz", - "integrity": "sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.18.tgz", + "integrity": "sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==", "optional": true }, "esbuild-linux-ppc64le": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.13.tgz", - "integrity": "sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.18.tgz", + "integrity": "sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==", "optional": true }, "esbuild-linux-riscv64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.13.tgz", - "integrity": "sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.18.tgz", + "integrity": "sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==", "optional": true }, "esbuild-linux-s390x": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.13.tgz", - "integrity": "sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.18.tgz", + "integrity": "sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==", "optional": true }, "esbuild-netbsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.13.tgz", - "integrity": "sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.18.tgz", + "integrity": "sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==", "optional": true }, "esbuild-openbsd-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.13.tgz", - "integrity": "sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.18.tgz", + "integrity": "sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==", "optional": true }, "esbuild-sunos-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.13.tgz", - "integrity": "sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.18.tgz", + "integrity": "sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==", "optional": true }, "esbuild-windows-32": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.13.tgz", - "integrity": "sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.18.tgz", + "integrity": "sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==", "optional": true }, "esbuild-windows-64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.13.tgz", - "integrity": "sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.18.tgz", + "integrity": "sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==", "optional": true }, "esbuild-windows-arm64": { - "version": "0.15.13", - "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.13.tgz", - "integrity": "sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg==", + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.18.tgz", + "integrity": "sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==", "optional": true }, "escalade": { diff --git a/package.json b/package.json index 614a8f1e..14b72a5a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "commander": "^9.4.1", "deepmerge": "^4.2.2", "enquirer": "^2.3.6", - "esbuild": "^0.15.13", + "esbuild": "^0.15.18", "expect": "^28.1.3", "http-proxy": "^1.18.1", "kleur": "^4.1.5", diff --git a/src/push/bundler.ts b/src/push/bundler.ts index 60c0bbff..ed5e2309 100644 --- a/src/push/bundler.ts +++ b/src/push/bundler.ts @@ -23,22 +23,23 @@ * */ -import path from 'path'; -import { stat, unlink, readFile } from 'fs/promises'; +import path, { normalize } from 'path'; +import { stat, unlink, readFile, writeFile } from 'fs/promises'; import { createWriteStream } from 'fs'; import * as esbuild from 'esbuild'; import archiver from 'archiver'; import { builtinModules } from 'module'; import { commonOptions, + EXTERNAL_MODULES, isBare, SyntheticsBundlePlugin, PluginData, } from './plugin'; +import { lcaTwoPaths } from './utils'; const SIZE_LIMIT_KB = 800; const BUNDLES_PATH = 'bundles'; -const EXTERNAL_MODULES = ['@elastic/synthetics']; function relativeToCwd(entry: string) { return path.relative(process.cwd(), entry); @@ -59,7 +60,7 @@ export class Bundler { entryPoints: { [absPath]: absPath, }, - plugins: [SyntheticsBundlePlugin(addToMap, EXTERNAL_MODULES)], + plugins: [SyntheticsBundlePlugin(addToMap)], }, }; const result = await esbuild.build(options); @@ -70,11 +71,11 @@ export class Bundler { resolvePath(bundlePath: string) { for (const mod of this.moduleMap.keys()) { - if (mod.startsWith(bundlePath)) { + if (mod.includes(bundlePath)) { return mod.substring(0, mod.lastIndexOf(path.extname(mod))); } } - return null; + throw new Error(`Could not find bundled code for ${bundlePath}`); } /** @@ -99,23 +100,34 @@ export class Bundler { ) { return raw; } - // If the module is not in node_modules, we need to go up the directory - // tree till we reach the bundles directory - let deep = bundlePath.split(path.sep).length; + // Resolve the path to the module from the bundles directory let resolvedpath = this.resolvePath(BUNDLES_PATH + '/' + dep); - // If its already part of the bundles directory, we don't need to go up - if (bundlePath.startsWith(BUNDLES_PATH)) { - deep -= 1; - resolvedpath = resolvedpath.replace(BUNDLES_PATH + '/', ''); + // Take LCA to find the relative path + const LCAPath = lcaTwoPaths(bundlePath, resolvedpath); + resolvedpath = resolvedpath.replace(LCAPath, ''); + bundlePath = bundlePath.replace(LCAPath, ''); + // Calculate the depth of the relative path to the module + const depth = bundlePath.split(path.sep).filter(Boolean).length - 1; + + // Resolve the path to the module from the bundles directory + let pathToModule = ''; + if (depth === 0) { + pathToModule = + './' + + (resolvedpath.charAt(0) === '/' + ? resolvedpath.substring(1) + : resolvedpath); + } else { + pathToModule = normalize('../'.repeat(depth) + resolvedpath); } - return raw.replace(dep, '.'.repeat(deep) + '/' + resolvedpath); + return raw.replace(dep, pathToModule); }); } getModulesPath(path: string) { const relativePath = relativeToCwd(path); - if (relativePath.startsWith('node_modules')) { - return relativePath.replace('node_modules', BUNDLES_PATH); + if (relativePath.includes('node_modules')) { + return relativePath.replaceAll('node_modules', BUNDLES_PATH); } return relativePath; } @@ -146,6 +158,7 @@ export class Bundler { await this.prepare(entry); await this.zip(output); const data = await this.encode(output); + // await writeFile('/tmp/new-synth.zip', data, 'base64'); await this.checkSize(output); await this.cleanup(output); return data; diff --git a/src/push/index.ts b/src/push/index.ts index 93736eea..4d7c27d0 100644 --- a/src/push/index.ts +++ b/src/push/index.ts @@ -62,10 +62,11 @@ export async function push(monitors: Monitor[], options: PushOptions) { } progress(`Pushing monitors for project: ${options.id}`); - const stackVersion = await getVersion(options); - const isV2 = semver.satisfies(stackVersion, '>=8.6.0'); + // const stackVersion = await getVersion(options); + // const isV2 = semver.satisfies(stackVersion, '>=8.6.0'); + const isV2 = false; if (!isV2) { - return await pushLegacy(monitors, options, stackVersion); + return await pushLegacy(monitors, options, '8.5.0' as any); } const local = getLocalMonitors(monitors); diff --git a/src/push/plugin.ts b/src/push/plugin.ts index e15d04ab..9005ac72 100644 --- a/src/push/plugin.ts +++ b/src/push/plugin.ts @@ -36,17 +36,17 @@ const DIST_DIR = join(ROOT_DIR, 'dist'); // Node modules directory of the package - /node_modules const SOURCE_NODE_MODULES = join(ROOT_DIR, 'node_modules'); +export const EXTERNAL_MODULES = ['@elastic/synthetics']; export function commonOptions(): esbuild.BuildOptions { return { bundle: true, - external: ['@elastic/synthetics'], + external: EXTERNAL_MODULES, minify: false, minifyIdentifiers: false, minifySyntax: false, minifyWhitespace: false, - treeShaking: false, keepNames: false, - logLevel: 'error', + logLevel: 'silent', platform: 'node', write: false, outExtension: { @@ -72,18 +72,17 @@ export const isBare = (str: string) => { // Avoid importing @elastic/synthetics package from source const isLocalSynthetics = (entryPath: string) => { - return entryPath.startsWith(SOURCE_DIR) || entryPath.startsWith(DIST_DIR); + return entryPath.includes(SOURCE_DIR) || entryPath.includes(DIST_DIR); }; // Avoid importing the local dependenceis of the @elastic/synthetics module // from source const isLocalSyntheticsModule = (str: string) => { - return str.startsWith(SOURCE_NODE_MODULES); + return str.includes(SOURCE_NODE_MODULES); }; export function SyntheticsBundlePlugin( - callback: PluginCallback, - external: string[] + callback: PluginCallback ): esbuild.Plugin { const visited = new Set(); @@ -95,7 +94,7 @@ export function SyntheticsBundlePlugin( }, onResolved: async resolved => { if ( - external.includes(resolved) || + EXTERNAL_MODULES.some(mod => resolved.includes(mod)) || isLocalSynthetics(resolved) || isLocalSyntheticsModule(resolved) ) { @@ -104,33 +103,24 @@ export function SyntheticsBundlePlugin( }; } + // Avoid running the bundler on the same module twice if (visited.has(resolved)) { return; } // Spin off another build to copy over the imported modules without bundling - if (resolved.includes('/node_modules/')) { - const result = await esbuild.build({ - ...commonOptions(), - entryPoints: [resolved], - bundle: false, - external: [], - }); + const result = await esbuild.build({ + ...commonOptions(), + entryPoints: [resolved], + bundle: false, + external: [], + }); + + callback({ + path: resolved, + contents: result.outputFiles[0].text, + }); - callback({ - path: resolved, - contents: result.outputFiles[0].text, - }); - } else { - // If it's a local file, read it and return the contents - // to preserve the source without modifications - try { - const contents = await readFile(resolved, 'utf-8'); - callback({ path: resolved, contents }); - } catch (e) { - throw new Error(`Could not read file ${resolved}`); - } - } visited.add(resolved); return; }, diff --git a/src/push/utils.ts b/src/push/utils.ts index a9d4f591..85bb104f 100644 --- a/src/push/utils.ts +++ b/src/push/utils.ts @@ -23,6 +23,7 @@ * */ +import path from 'path'; import { progress, removeTrailingSlash } from '../helpers'; import { green, red, grey, yellow } from 'kleur/colors'; import { PushOptions } from '../common_types'; @@ -75,3 +76,18 @@ export function generateURL(options: PushOptions, operation: Operation) { throw new Error('Invalid operation'); } } + +const SEPARATOR = path.sep; +export function lcaTwoPaths(path1, path2) { + const parts1 = path1.split(SEPARATOR); + const parts2 = path2.split(SEPARATOR); + const commonParts = []; + + for (let i = 0; i < parts1.length; i++) { + if (parts1[i] !== parts2[i]) { + break; + } + commonParts.push(parts1[i]); + } + return commonParts.join(SEPARATOR); +} diff --git a/tsconfig.json b/tsconfig.json index 1605b9ae..64b6427a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "noImplicitOverride": true, "sourceMap": true, "outDir": "dist", - "target": "es2020", + "target": "ES2021", "module": "commonjs" }, "include": ["src/**/*"] From 478fdb069bdfbfa754ffeef2343b92e7af5c2bce Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Thu, 8 Dec 2022 06:37:40 -0800 Subject: [PATCH 3/3] fix lint --- src/push/bundler.ts | 3 +-- src/push/index.ts | 7 +++---- src/push/plugin.ts | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/push/bundler.ts b/src/push/bundler.ts index ed5e2309..983193e7 100644 --- a/src/push/bundler.ts +++ b/src/push/bundler.ts @@ -24,7 +24,7 @@ */ import path, { normalize } from 'path'; -import { stat, unlink, readFile, writeFile } from 'fs/promises'; +import { stat, unlink, readFile } from 'fs/promises'; import { createWriteStream } from 'fs'; import * as esbuild from 'esbuild'; import archiver from 'archiver'; @@ -158,7 +158,6 @@ export class Bundler { await this.prepare(entry); await this.zip(output); const data = await this.encode(output); - // await writeFile('/tmp/new-synth.zip', data, 'base64'); await this.checkSize(output); await this.cleanup(output); return data; diff --git a/src/push/index.ts b/src/push/index.ts index 4d7c27d0..93736eea 100644 --- a/src/push/index.ts +++ b/src/push/index.ts @@ -62,11 +62,10 @@ export async function push(monitors: Monitor[], options: PushOptions) { } progress(`Pushing monitors for project: ${options.id}`); - // const stackVersion = await getVersion(options); - // const isV2 = semver.satisfies(stackVersion, '>=8.6.0'); - const isV2 = false; + const stackVersion = await getVersion(options); + const isV2 = semver.satisfies(stackVersion, '>=8.6.0'); if (!isV2) { - return await pushLegacy(monitors, options, '8.5.0' as any); + return await pushLegacy(monitors, options, stackVersion); } const local = getLocalMonitors(monitors); diff --git a/src/push/plugin.ts b/src/push/plugin.ts index 9005ac72..b177cc40 100644 --- a/src/push/plugin.ts +++ b/src/push/plugin.ts @@ -24,7 +24,6 @@ */ import { join } from 'path'; -import { readFile } from 'fs/promises'; import * as esbuild from 'esbuild'; import NodeResolvePlugin from '@esbuild-plugins/node-resolve';