-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { createNodes, RollupPluginOptions } from './src/plugins/plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`@nx/rollup/plugin non-root project should create nodes 1`] = ` | ||
{ | ||
"projects": { | ||
"mylib": { | ||
"root": "mylib", | ||
"targets": { | ||
"build": { | ||
"cache": true, | ||
"command": "rollup -c rollup.config.js", | ||
"dependsOn": [ | ||
"^build", | ||
], | ||
"inputs": [ | ||
"production", | ||
"^production", | ||
], | ||
"options": { | ||
"cwd": "mylib", | ||
}, | ||
"outputs": [ | ||
"{workspaceRoot}/mylib/build", | ||
"{workspaceRoot}/mylib/dist", | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`@nx/rollup/plugin root project should create nodes 1`] = ` | ||
{ | ||
"projects": { | ||
".": { | ||
"root": ".", | ||
"targets": { | ||
"build": { | ||
"cache": true, | ||
"command": "rollup -c rollup.config.js", | ||
"dependsOn": [ | ||
"^build", | ||
], | ||
"inputs": [ | ||
"production", | ||
"^production", | ||
], | ||
"options": { | ||
"cwd": ".", | ||
}, | ||
"outputs": [ | ||
"{workspaceRoot}/dist", | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { type CreateNodesContext, joinPathFragments } from '@nx/devkit'; | ||
import { createNodes } from './plugin'; | ||
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs'; | ||
|
||
describe('@nx/rollup/plugin', () => { | ||
let createNodesFunction = createNodes[1]; | ||
let context: CreateNodesContext; | ||
let cwd = process.cwd(); | ||
|
||
describe('root project', () => { | ||
const tempFs = new TempFs('test'); | ||
|
||
beforeEach(() => { | ||
context = { | ||
nxJsonConfiguration: { | ||
targetDefaults: { | ||
build: { | ||
cache: false, | ||
inputs: ['foo', '^foo'], | ||
}, | ||
}, | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*'], | ||
production: ['!{projectRoot}/**/*.spec.ts'], | ||
}, | ||
}, | ||
workspaceRoot: tempFs.tempDir, | ||
}; | ||
|
||
tempFs.createFileSync('package.json', JSON.stringify({ name: 'mylib' })); | ||
tempFs.createFileSync( | ||
'src/index.js', | ||
`export function main() { | ||
console.log("hello world"); | ||
}` | ||
); | ||
tempFs.createFileSync( | ||
'rollup.config.js', | ||
` | ||
const config = { | ||
input: 'src/index.js', | ||
output: [ | ||
{ | ||
file: 'dist/bundle.js', | ||
format: 'cjs', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: 'dist/bundle.es.js', | ||
format: 'es', | ||
sourcemap: true | ||
} | ||
], | ||
plugins: [], | ||
}; | ||
module.exports = config; | ||
` | ||
); | ||
|
||
process.chdir(tempFs.tempDir); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetModules(); | ||
tempFs.cleanup(); | ||
process.chdir(cwd); | ||
}); | ||
|
||
it('should create nodes', async () => { | ||
// ACT | ||
const nodes = await createNodesFunction( | ||
'rollup.config.js', | ||
{ | ||
buildTargetName: 'build', | ||
}, | ||
context | ||
); | ||
|
||
// ASSERT | ||
expect(nodes).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe('non-root project', () => { | ||
const tempFs = new TempFs('test'); | ||
|
||
beforeEach(() => { | ||
context = { | ||
nxJsonConfiguration: { | ||
namedInputs: { | ||
default: ['{projectRoot}/**/*'], | ||
production: ['!{projectRoot}/**/*.spec.ts'], | ||
}, | ||
}, | ||
workspaceRoot: tempFs.tempDir, | ||
}; | ||
|
||
tempFs.createFileSync( | ||
'mylib/package.json', | ||
JSON.stringify({ name: 'mylib' }) | ||
); | ||
tempFs.createFileSync( | ||
'mylib/src/index.js', | ||
`export function main() { | ||
console.log("hello world"); | ||
}` | ||
); | ||
tempFs.createFileSync( | ||
'mylib/rollup.config.js', | ||
` | ||
const config = { | ||
input: 'src/index.js', | ||
output: [ | ||
{ | ||
file: 'build/bundle.js', | ||
format: 'cjs', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: 'dist/bundle.es.js', | ||
format: 'es', | ||
sourcemap: true | ||
} | ||
], | ||
plugins: [], | ||
}; | ||
module.exports = config; | ||
` | ||
); | ||
|
||
process.chdir(tempFs.tempDir); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetModules(); | ||
tempFs.cleanup(); | ||
process.chdir(cwd); | ||
}); | ||
|
||
it('should create nodes', async () => { | ||
// ACT | ||
const nodes = await createNodesFunction( | ||
'mylib/rollup.config.js', | ||
{ | ||
buildTargetName: 'build', | ||
}, | ||
context | ||
); | ||
|
||
// ASSERT | ||
expect(nodes).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.