Skip to content
Open
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
30 changes: 23 additions & 7 deletions next-cloudinary/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
module.exports = api => {
const presets = []
const { version } = require("./package.json");

if ( api.env('test') ) {
presets.push([['@babel/preset-env', {targets: {node: 'current'}}]]);
module.exports = (api) => {
const presets = [];

if (api.env("test")) {
presets.push([["@babel/preset-env", { targets: { node: "current" } }]]);
}

presets.push(['@babel/preset-react', { runtime: 'automatic' }]);
presets.push(['@babel/preset-typescript']);
presets.push(["@babel/preset-react", { runtime: "automatic" }]);
presets.push(["@babel/preset-typescript"]);

return {
presets
presets,
plugins: [
// Inline the version used by src/constants/analytics.ts at build time instead of bundling package.json.
function inlineNextCloudinaryVersion() {
return {
name: "inline-next-cloudinary-version",
visitor: {
ReferencedIdentifier(path) {
if (path.node.name !== "__NEXT_CLOUDINARY_VERSION__") return;
path.replaceWith({ type: "StringLiteral", value: version });
},
},
};
},
],
};
};
10 changes: 6 additions & 4 deletions next-cloudinary/src/constants/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import nextPkg from 'next/package.json';
import pkg from '../../package.json';
import { version as nextVersion } from 'next/package.json';

// Injected at build time to avoid bundling this package's package.json
declare const __NEXT_CLOUDINARY_VERSION__: string;

// Detect if this project was created via create-cloudinary-react CLI (Integrations)
// copied from https://github.com/cloudinary/frontend-frameworks/commit/00a8eb2b133c772fb6f54d840eba0012286b70b2#diff-9bc0325d4ce5c8af9b3be68a361f186552b51da8274a7a2f214f7deaa9b245af
Expand All @@ -18,8 +20,8 @@ const isCLIDetected = isCLI();
// and use sdk code 'I' ('Next CLI' integration) instead of 'V' (Next.js sdk)
export const NEXT_CLOUDINARY_ANALYTICS_PRODUCT_ID = (isCLIDetected ? 'B' : 'A');
export const NEXT_CLOUDINARY_ANALYTICS_ID = (isCLIDetected ? 'I' : 'V');
export const NEXT_VERSION = normalizeVersion(nextPkg.version);
export const NEXT_CLOUDINARY_VERSION = normalizeVersion(pkg.version);
export const NEXT_VERSION = normalizeVersion(nextVersion);
export const NEXT_CLOUDINARY_VERSION = normalizeVersion(__NEXT_CLOUDINARY_VERSION__);

function normalizeVersion(version: string) {
let normalized = version;
Expand Down
9 changes: 9 additions & 0 deletions next-cloudinary/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';
import pkg from './package.json';

export default defineConfig({
// Mirror the Babel replacement for src/constants/analytics.ts during tests
define: {
__NEXT_CLOUDINARY_VERSION__: JSON.stringify(pkg.version),
},
});