Skip to content

Commit 4b9550c

Browse files
committed
fix: outDir was recursively copied into itself
1 parent 448a60a commit 4b9550c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/copy-addon.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ export default function copyOtherFiles(program: Program, emittedFiles: string[]
2121
const srcDir = program.getCommonSourceDirectory()
2222
if (!srcDir) throw Error('Cannot copy: issue with internal typescript method `getCommonSourceDirectory`')
2323

24-
const otherFiles = matchAllFilesBut(srcDir, ['**/*.ts'])
25-
const copiedFiles: string[] = [] // Track copied files to list them later if needed
24+
// Exclude typescript files and outDir if previously emitted in the same folder
25+
const otherFiles = matchAllFilesBut(srcDir, ['**/*.ts', outDir])
26+
27+
// Track copied files to list them later if needed
28+
const copiedFiles: string[] = []
2629

2730
for (const srcFile of otherFiles) {
2831
const destFile = resolve(outDir, relative(srcDir, srcFile))

test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,25 @@ describe('Copy', () => {
142142

143143
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringMatching(/override.*data\.json/))
144144
})
145+
146+
test('do not recursively copy outDir to outDir', () => {
147+
// tslint:disable-next-line: no-shadowed-variable
148+
const basePath = join(__dirname, '__fixtures__', 'src')
149+
// tslint:disable-next-line: no-shadowed-variable
150+
const configFilePath = '../tsconfig.fixture.json'
151+
152+
build({
153+
basePath,
154+
configFilePath,
155+
copyOtherToOutDir: true,
156+
compilerOptions: {
157+
rootDir: '.',
158+
outDir: 'dist',
159+
},
160+
exclude: ['**/excluded'],
161+
})
162+
163+
const distInDist = join(basePath, 'dist', 'dist')
164+
expect(existsSync(distInDist)).toBe(false)
165+
})
145166
})

0 commit comments

Comments
 (0)