Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support rollup.config.ts #28240

Merged
merged 6 commits into from
Dec 12, 2024
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
3 changes: 2 additions & 1 deletion packages/rollup/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"nx",
"typescript",
"@swc/core", // Installed to workspace and only used in swc() plugin
"postcss"
"postcss",
"@rollup/plugin-typescript"
]
}
]
Expand Down
7 changes: 4 additions & 3 deletions packages/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
"migrations": "./migrations.json"
},
"dependencies": {
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^12.1.0",
"autoprefixer": "^10.4.9",
"minimatch": "9.0.3",
"picocolors": "^1.1.0",
Expand All @@ -42,9 +45,7 @@
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js"
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
109 changes: 109 additions & 0 deletions packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,61 @@ exports[`@nx/rollup/plugin non-root project should create nodes 1`] = `
]
`;

exports[`@nx/rollup/plugin non-root project should create nodes 2`] = `
[
[
"mylib/rollup.config.cts",
{
"projects": {
"mylib": {
"root": "mylib",
"targets": {
"build": {
"cache": true,
"command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript",
"dependsOn": [
"^build",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"rollup",
],
},
],
"metadata": {
"description": "Run Rollup",
"help": {
"command": "npx rollup --help",
"example": {
"options": {
"sourcemap": true,
"watch": true,
},
},
},
"technologies": [
"rollup",
],
},
"options": {
"cwd": "mylib",
},
"outputs": [
"{workspaceRoot}/mylib/build",
"{workspaceRoot}/mylib/dist",
],
},
},
},
},
},
],
]
`;

exports[`@nx/rollup/plugin root project should create nodes 1`] = `
[
[
Expand Down Expand Up @@ -108,3 +163,57 @@ exports[`@nx/rollup/plugin root project should create nodes 1`] = `
],
]
`;

exports[`@nx/rollup/plugin root project should create nodes 2`] = `
[
[
"rollup.config.cts",
{
"projects": {
".": {
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript",
"dependsOn": [
"^build",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"rollup",
],
},
],
"metadata": {
"description": "Run Rollup",
"help": {
"command": "npx rollup --help",
"example": {
"options": {
"sourcemap": true,
"watch": true,
},
},
},
"technologies": [
"rollup",
],
},
"options": {
"cwd": ".",
},
"outputs": [
"{workspaceRoot}/dist",
],
},
},
},
},
},
],
]
`;
12 changes: 6 additions & 6 deletions packages/rollup/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('@nx/rollup/plugin', () => {
let context: CreateNodesContext;
let cwd = process.cwd();

describe('root project', () => {
describe.each(['js', 'ts'])('root project', (extname) => {
const tempFs = new TempFs('test');

beforeEach(() => {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('@nx/rollup/plugin', () => {
// is that the hash is different after updating the
// config file. The actual config read is mocked below.
tempFs.createFileSync(
'rollup.config.cjs',
`rollup.config.c${extname}`,
JSON.stringify(rollupConfigOptions)
);
tempFs.createFileSync('package.json', JSON.stringify({ name: 'mylib' }));
Expand All @@ -77,7 +77,7 @@ describe('@nx/rollup/plugin', () => {
it('should create nodes', async () => {
// ACT
const nodes = await createNodesFunction(
['rollup.config.cjs'],
[`rollup.config.c${extname}`],
{
buildTargetName: 'build',
},
Expand All @@ -89,7 +89,7 @@ describe('@nx/rollup/plugin', () => {
});
});

describe('non-root project', () => {
describe.each(['js', 'ts'])('non-root project', (extname) => {
const tempFs = new TempFs('test');

beforeEach(() => {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('@nx/rollup/plugin', () => {
// is that the hash is different after updating the
// config file. The actual config read is mocked below.
tempFs.createFileSync(
'mylib/rollup.config.cjs',
`mylib/rollup.config.c${extname}`,
JSON.stringify(rollupConfigOptions)
);
tempFs.createFileSync(
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('@nx/rollup/plugin', () => {
it('should create nodes', async () => {
// ACT
const nodes = await createNodesFunction(
['mylib/rollup.config.cjs'],
[`mylib/rollup.config.c${extname}`],
{
buildTargetName: 'build',
},
Expand Down
8 changes: 6 additions & 2 deletions packages/rollup/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface RollupPluginOptions {
buildTargetName?: string;
}

const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs}';
const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs,ts,cts,mts}';

export const createNodes: CreateNodes<RollupPluginOptions> = [
rollupConfigGlob,
Expand Down Expand Up @@ -182,7 +182,11 @@ async function buildRollupTarget(

const targets: Record<string, TargetConfiguration> = {};
targets[options.buildTargetName] = {
command: `rollup -c ${basename(configFilePath)}`,
command: `rollup -c ${basename(configFilePath)}${
configFilePath.endsWith('ts')
? ' --configPlugin @rollup/plugin-typescript'
: ''
}`,
options: { cwd: projectRoot },
cache: true,
dependsOn: [`^${options.buildTargetName}`],
Expand Down
Loading