Skip to content

Commit

Permalink
Merge pull request #52 from ninetailed-inc/fix/rollup-replace-package…
Browse files Browse the repository at this point in the history
…-version

Replace package version env var in all projects
  • Loading branch information
BraunreutherA authored Jun 10, 2024
2 parents a4d8d3d + eeacc6f commit 19d87cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/plugins/preview/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"project": "packages/plugins/preview/package.json",
"entryFile": "packages/plugins/preview/src/index.ts",
"external": [],
"rollupConfig": "@nx/react/plugins/bundle-rollup",
"rollupConfig": "packages/plugins/preview/rollup.config.cjs",
"format": ["cjs", "esm"],
"assets": [
{
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/preview/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const nrwlConfig = require('@nx/react/plugins/bundle-rollup');
const withPackageVersion = require('../../../withPackageVersion');

module.exports = (config) => {
return withPackageVersion(nrwlConfig(config));
};
22 changes: 2 additions & 20 deletions packages/sdks/shared/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
const nrwlConfig = require('@nx/react/plugins/bundle-rollup');
const replace = require('@rollup/plugin-replace');
require('dotenv').config({ path: '../../../.env.local' });
const withPackageVersion = require('../../../withPackageVersion');

module.exports = (config) => {
if (!process.env.NX_PACKAGE_VERSION) {
throw new Error('NX_PACKAGE_VERSION is not set');
}

const nxConfig = nrwlConfig(config);
return {
...nxConfig,
plugins: [
...nxConfig.plugins,
replace({
"process.env['NX_PACKAGE_VERSION']": JSON.stringify(
process.env.NX_PACKAGE_VERSION
),
delimiters: ['', ''],
preventAssignment: true,
}),
],
};
return withPackageVersion(nrwlConfig(config));
};
30 changes: 30 additions & 0 deletions withPackageVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path');
const devkit = require('@nrwl/devkit');

const replace = require('@rollup/plugin-replace');

require('dotenv').config({
path: path.join(devkit.workspaceRoot, '.env.local'),
});

const withPackageVersion = (config) => {
if (!process.env.NX_PACKAGE_VERSION) {
throw new Error('NX_PACKAGE_VERSION is not set');
}

return {
...config,
plugins: [
...(config.plugins || []),
replace({
"process.env['NX_PACKAGE_VERSION']": JSON.stringify(
process.env.NX_PACKAGE_VERSION
),
delimiters: ['', ''],
preventAssignment: true,
}),
],
};
};

module.exports = withPackageVersion;

0 comments on commit 19d87cd

Please sign in to comment.