Skip to content

Commit

Permalink
feat: expose cwd in input options (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnx committed Mar 29, 2024
1 parent 15cedc9 commit ba42b29
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/rolldown/src/options/input-options-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createInputOptionsAdapter(
// @ts-expect-error
bindingifyPlugin(plugin, options),
),
cwd: process.cwd(),
cwd: inputOptions.cwd ?? process.cwd(),
external: inputOptions.external ? options.external : undefined,
resolve: options.resolve,
}
Expand Down
1 change: 1 addition & 0 deletions packages/rolldown/src/options/input-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface InputOptions {
plugins?: Plugin[]
external?: RollupInputOptions['external']
resolve?: RolldownResolveOptions
cwd?: string
}

export type RolldownResolveOptions = Omit<BindingResolveOptions, 'alias'> & {
Expand Down
17 changes: 4 additions & 13 deletions packages/rolldown/tests/cli/fixtures/basic/rolldown.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

export default {
// input: 'src/index.js',
input: path.resolve(__dirname, 'src/index.js'),
input: 'src/index.js',
output: [
{
// dir: 'build',
// file: 'build/bundle.js',
dir: path.resolve(__dirname, 'build'),
file: path.resolve(__dirname, 'build/bundle.js'),
dir: 'build',
file: 'build/bundle.js',
},
],
resolve: {
conditionNames: ['import'],
alias: {
// modules: 'src/modules',
modules: path.resolve(__dirname, 'src/modules'),
modules: 'src/modules',
},
},
}
8 changes: 2 additions & 6 deletions packages/rolldown/tests/fixture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ function main() {
async function compileFixture(fixturePath: string, config: TestConfig) {
let outputOptions: OutputOptions = config.config?.output ?? {}
delete config.config?.output
outputOptions = {
dir: outputOptions.dir ?? nodePath.join(fixturePath, 'dist'),
...outputOptions,
}

const inputOptions: InputOptions = {
input: config.config?.input ?? nodePath.join(fixturePath, 'main.js'),
input: 'main.js',
cwd: fixturePath,
...config.config,
}
const build = await rolldown(inputOptions)
Expand Down
3 changes: 1 addition & 2 deletions packages/rolldown/tests/fixtures/input/array/_config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { defineTest } from '@tests'
import path from 'node:path'
import { expect } from 'vitest'
import { getOutputChunkNames } from '@tests/utils'

export default defineTest({
config: {
input: [path.join(__dirname, 'main.js'), path.join(__dirname, 'entry.js')],
input: ['main.js', 'entry.js'],
},
afterTest: function (output) {
expect(getOutputChunkNames(output)).toMatchInlineSnapshot(`
Expand Down
5 changes: 2 additions & 3 deletions packages/rolldown/tests/fixtures/input/object/_config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { defineTest } from '@tests'
import path from 'node:path'
import { expect } from 'vitest'
import { getOutputChunkNames } from '@tests/utils'

export default defineTest({
config: {
input: {
main: path.join(__dirname, 'main.js'),
entry: path.join(__dirname, 'entry.js'),
main: 'main.js',
entry: 'entry.js',
},
},
afterTest: (output) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/rolldown/tests/fixtures/input/string/_config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { defineTest } from '@tests'
import path from 'node:path'
import { expect } from 'vitest'
import { getOutputChunkNames } from '@tests/utils'

export default defineTest({
config: {
input: path.join(__dirname, 'main.js'),
input: 'main.js',
},
afterTest: (output) => {
expect(getOutputChunkNames(output)).toStrictEqual(['main.js'])
Expand Down
3 changes: 1 addition & 2 deletions packages/rolldown/tests/fixtures/sourcemap/inner/_config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// cSpell:disable
import path from 'node:path'
import { expect } from 'vitest'
import { getOutputFileNames } from '@tests/utils'
import { defineTest } from '@tests'

export default defineTest({
config: {
input: [path.join(__dirname, 'main.js')],
input: ['main.js'],
output: {
sourcemap: true,
},
Expand Down

0 comments on commit ba42b29

Please sign in to comment.