Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fetch-depth: 0 # Full history needed for yarn version to find ancestor with master/main
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "24"
node-version-file: "package.json"
registry-url: "https://registry.npmjs.org"

- name: Validate and set channel
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"packages/published/*"
],
"volta": {
"node": "20.19.4",
"node": "24.14.1",
Comment thread
tyffical marked this conversation as resolved.
Resolved
"yarn": "1.22.19"
},
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages/factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"@dd/output-plugin": "workspace:*",
"@dd/rum-plugin": "workspace:*",
"chalk": "2.3.1",
"semver": "7.7.2",
"unplugin": "2.3.11"
},
"devDependencies": {
"@types/semver": "7.5.8",
"typescript": "5.4.3"
}
}
48 changes: 48 additions & 0 deletions packages/factory/src/helpers/vite-version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import vitePluginPackage from '../../../published/vite-plugin/package.json';

import { getUnsupportedViteWarning, MAX_VITE_MAJOR, MIN_VITE_VERSION } from './vite-version';

const floor = MIN_VITE_VERSION.split('.').slice(0, 2).join('.');
const deprecated = (version: string) =>
`Vite ${version} is deprecated in Datadog's Vite plugin: please upgrade to Vite ${floor} or later.`;
const untested = (version: string) =>
`Datadog's Vite plugin is tested up to Vite ${MAX_VITE_MAJOR}.x (found ${version}).`;

describe('getUnsupportedViteWarning', () => {
const cases: { version: unknown; expected: string | undefined }[] = [
{ version: '4.5.3', expected: deprecated('4.5.3') },
{ version: '5.4.21', expected: deprecated('5.4.21') },
{ version: '6.0.0', expected: deprecated('6.0.0') },
{ version: '6.3.9', expected: deprecated('6.3.9') },
{ version: '6.4.0-beta.1', expected: deprecated('6.4.0-beta.1') },
{ version: MIN_VITE_VERSION, expected: undefined },
{ version: '6.4.3', expected: undefined },
{ version: '6.10.0', expected: undefined },
{ version: '7.0.0-beta.1', expected: undefined },
{ version: '8.3.4', expected: undefined },
{ version: '9.0.0', expected: untested('9.0.0') },
{ version: '9.0.0-beta.1', expected: untested('9.0.0-beta.1') },
{ version: '10.1.0', expected: untested('10.1.0') },
{ version: 'v5.4.21', expected: deprecated('v5.4.21') },
{ version: '6.3', expected: undefined },
{ version: '', expected: undefined },
{ version: 'not-a-version', expected: undefined },
{ version: undefined, expected: undefined },
{ version: 5, expected: undefined },
];

test.each(cases)('Should return the expected warning for $version', ({ version, expected }) => {
const warning = getUnsupportedViteWarning(version);
expect(warning).toBe(expected);
});

// Versions below the floor stay in the peer range while deprecated.
test('Should share its upper bound with the peer range the Vite plugin declares', () => {
const upperBound = new RegExp(`<= ?${MAX_VITE_MAJOR}\\.x$`);
expect(vitePluginPackage.peerDependencies.vite).toMatch(upperBound);
});
});
29 changes: 29 additions & 0 deletions packages/factory/src/helpers/vite-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import semver from 'semver';

// The oldest line Vite still patches: https://vite.dev/releases#supported-versions
export const MIN_VITE_VERSION = '6.4.0';
export const MAX_VITE_MAJOR = 8;

const MIN_VITE_LINE = `${semver.major(MIN_VITE_VERSION)}.${semver.minor(MIN_VITE_VERSION)}`;

// An unreadable version is left alone: the warning is advice, not a gate.
export const getUnsupportedViteWarning = (version: unknown): string | undefined => {
const parsed = typeof version === 'string' ? semver.parse(version) : null;
if (!parsed) {
return undefined;
}

if (semver.lt(parsed, MIN_VITE_VERSION)) {
return `Vite ${version} is deprecated in Datadog's Vite plugin: please upgrade to Vite ${MIN_VITE_LINE} or later.`;
}

if (parsed.major > MAX_VITE_MAJOR) {
return `Datadog's Vite plugin is tested up to Vite ${MAX_VITE_MAJOR}.x (found ${version}).`;
}

return undefined;
};
60 changes: 60 additions & 0 deletions packages/factory/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import type { PluginOptions, Options } from '@dd/core/types';
import { PLUGIN_NAME as ERROR_TRACKING_PLUGIN_NAME } from '@dd/error-tracking-plugin';
import { getUnsupportedViteWarning } from '@dd/factory/helpers/vite-version';
import { buildPluginFactory } from '@dd/factory';

const invokeFactory = (opts: Options): PluginOptions[] => {
Expand Down Expand Up @@ -93,4 +94,63 @@ describe('Factory', () => {
expect(hasPlugin(plugins, 'output')).toBe(true);
});
});

describe('Vite version', () => {
let warn: jest.SpyInstance;

beforeEach(() => {
warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
warn.mockRestore();
});

const cases: {
description: string;
framework: 'vite' | 'esbuild';
version: string;
warns: boolean;
}[] = [
{ description: 'Vite 5', framework: 'vite', version: '5.4.21', warns: true },
{ description: 'Vite 6.3', framework: 'vite', version: '6.3.5', warns: true },
{ description: 'Vite 6.4', framework: 'vite', version: '6.4.3', warns: false },
{ description: 'Vite 8', framework: 'vite', version: '8.3.4', warns: false },
{ description: 'Vite 9', framework: 'vite', version: '9.0.0', warns: true },
{
description: 'another bundler with a low version',
framework: 'esbuild',
version: '0.25.8',
warns: false,
},
];

test.each(cases)(
'Should warn about an unsupported Vite only when it is one: $description',
({ framework, version, warns }) => {
const factory = buildPluginFactory({ bundler: { version }, version: '1.0.0' });
factory.raw({ logLevel: 'warn' }, { framework });
const warnings = warn.mock.calls.map(([message]) => String(message));
const viteWarnings = warnings.filter((message) =>
message.includes("Datadog's Vite plugin"),
);
const expected = getUnsupportedViteWarning(version);
const matching = viteWarnings.filter(
(message) => expected !== undefined && message.endsWith(expected),
);
const count = warns ? 1 : 0;
expect(viteWarnings).toHaveLength(count);
expect(matching).toHaveLength(count);
},
);

test('Should not print the warning when logs are off', () => {
const factory = buildPluginFactory({
bundler: { version: '5.4.21' },
version: '1.0.0',
});
factory.raw({ logLevel: 'none' }, { framework: 'vite' });
expect(warn).not.toHaveBeenCalled();
});
});
});
7 changes: 7 additions & 0 deletions packages/factory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import chalk from 'chalk';

import { validateOptions } from './validate';
import { getContext } from './helpers/context';
import { getUnsupportedViteWarning } from './helpers/vite-version';
import { wrapGetPlugins } from './helpers/wrapPlugins';
import { ALL_ENVS, HOST_NAME } from '@dd/core/constants';
import { notifyOnEnvOverrides } from '@dd/core/helpers/env';
Expand Down Expand Up @@ -136,6 +137,12 @@ export const buildPluginFactory = ({
const log = context.getLogger('factory');
const timeInit = log.time('Plugins initialization', { start: pluginStart });

const viteWarning =
bundlerName === 'vite' ? getUnsupportedViteWarning(bundlerVersion) : undefined;
if (viteWarning) {
log.warn(viteWarning);
}

context.pluginNames.push(HOST_NAME);

const pluginsToAdd: [name: string, GetPlugins | GetCustomPlugins | GetInternalPlugins][] =
Expand Down
1 change: 1 addition & 0 deletions packages/published/esbuild-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"p-queue": "6.6.2",
"picomatch": "4.0.7",
"pretty-bytes": "5.6.0",
"semver": "7.7.2",
"simple-git": "4.0.2",
"unplugin": "2.3.11"
},
Expand Down
1 change: 1 addition & 0 deletions packages/published/rollup-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"p-queue": "6.6.2",
"picomatch": "4.0.7",
"pretty-bytes": "5.6.0",
"semver": "7.7.2",
"simple-git": "4.0.2",
"unplugin": "2.3.11"
},
Expand Down
1 change: 1 addition & 0 deletions packages/published/rspack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"p-queue": "6.6.2",
"picomatch": "4.0.7",
"pretty-bytes": "5.6.0",
"semver": "7.7.2",
"simple-git": "4.0.2",
"unplugin": "2.3.11"
},
Expand Down
1 change: 1 addition & 0 deletions packages/published/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"p-queue": "6.6.2",
"picomatch": "4.0.7",
"pretty-bytes": "5.6.0",
"semver": "7.7.2",
"simple-git": "4.0.2",
"unplugin": "2.3.11"
},
Expand Down
1 change: 1 addition & 0 deletions packages/published/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"p-queue": "6.6.2",
"picomatch": "4.0.7",
"pretty-bytes": "5.6.0",
"semver": "7.7.2",
"simple-git": "4.0.2",
"unplugin": "2.3.11"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/_jest/nockInterceptors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const runInLeakDir = (leakDir: string, fixtureGlobals: string, setupFilesAfterEn
};

// Node 22 handles the same leak without touching the interceptors, so neither case can tell
// anything apart there. They run before Node 22, which covers the Node 20 the repo pins.
// anything apart there. They only run on a Node older than 22.
const nodeMajorVersion = process.versions.node.split('.')[0];
const describeBeforeNode22 = Number(nodeMajorVersion) < 22 ? describe : describe.skip;
const INTERCEPTOR_WARNING = /JEST-01.*accessed on \[\w*Interceptor\]/;
Expand Down
25 changes: 16 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,7 @@ __metadata:
pretty-bytes: "npm:5.6.0"
rollup: "npm:4.60.4"
rollup-plugin-esbuild: "npm:6.1.1"
semver: "npm:7.7.2"
simple-git: "npm:4.0.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
Expand Down Expand Up @@ -1772,6 +1773,7 @@ __metadata:
pretty-bytes: "npm:5.6.0"
rollup: "npm:4.60.4"
rollup-plugin-esbuild: "npm:6.1.1"
semver: "npm:7.7.2"
simple-git: "npm:4.0.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
Expand Down Expand Up @@ -1824,6 +1826,7 @@ __metadata:
pretty-bytes: "npm:5.6.0"
rollup: "npm:4.60.4"
rollup-plugin-esbuild: "npm:6.1.1"
semver: "npm:7.7.2"
simple-git: "npm:4.0.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
Expand Down Expand Up @@ -1879,6 +1882,7 @@ __metadata:
pretty-bytes: "npm:5.6.0"
rollup: "npm:4.60.4"
rollup-plugin-esbuild: "npm:6.1.1"
semver: "npm:7.7.2"
simple-git: "npm:4.0.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
Expand Down Expand Up @@ -1931,6 +1935,7 @@ __metadata:
pretty-bytes: "npm:5.6.0"
rollup: "npm:4.60.4"
rollup-plugin-esbuild: "npm:6.1.1"
semver: "npm:7.7.2"
simple-git: "npm:4.0.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
Expand Down Expand Up @@ -2028,7 +2033,9 @@ __metadata:
"@dd/metrics-plugin": "workspace:*"
"@dd/output-plugin": "workspace:*"
"@dd/rum-plugin": "workspace:*"
"@types/semver": "npm:7.5.8"
chalk: "npm:2.3.1"
semver: "npm:7.7.2"
typescript: "npm:5.4.3"
unplugin: "npm:2.3.11"
languageName: unknown
Expand Down Expand Up @@ -4262,7 +4269,7 @@ __metadata:
languageName: node
linkType: hard

"@types/semver@npm:^7.5.0":
"@types/semver@npm:7.5.8, @types/semver@npm:^7.5.0":
version: 7.5.8
resolution: "@types/semver@npm:7.5.8"
checksum: 10/3496808818ddb36deabfe4974fd343a78101fa242c4690044ccdc3b95dcf8785b494f5d628f2f47f38a702f8db9c53c67f47d7818f2be1b79f2efb09692e1178
Expand Down Expand Up @@ -10224,21 +10231,21 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^6.0.0, semver@npm:^6.3.1":
version: 6.3.1
resolution: "semver@npm:6.3.1"
"semver@npm:7.7.2, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.7.2":
version: 7.7.2
resolution: "semver@npm:7.7.2"
bin:
semver: bin/semver.js
checksum: 10/1ef3a85bd02a760c6ef76a45b8c1ce18226de40831e02a00bad78485390b98b6ccaa31046245fc63bba4a47a6a592b6c7eedc65cc47126e60489f9cc1ce3ed7e
checksum: 10/7a24cffcaa13f53c09ce55e05efe25cd41328730b2308678624f8b9f5fc3093fc4d189f47950f0b811ff8f3c3039c24a2c36717ba7961615c682045bf03e1dda
languageName: node
linkType: hard

"semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.7.2":
version: 7.7.2
resolution: "semver@npm:7.7.2"
"semver@npm:^6.0.0, semver@npm:^6.3.1":
version: 6.3.1
resolution: "semver@npm:6.3.1"
bin:
semver: bin/semver.js
checksum: 10/7a24cffcaa13f53c09ce55e05efe25cd41328730b2308678624f8b9f5fc3093fc4d189f47950f0b811ff8f3c3039c24a2c36717ba7961615c682045bf03e1dda
checksum: 10/1ef3a85bd02a760c6ef76a45b8c1ce18226de40831e02a00bad78485390b98b6ccaa31046245fc63bba4a47a6a592b6c7eedc65cc47126e60489f9cc1ce3ed7e
languageName: node
linkType: hard

Expand Down
Loading