-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
194 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@builder.io/qwik': minor | ||
--- | ||
|
||
FEAT: add monorepo support to the `qwik add` command by adding an `outDir` param |
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
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,84 @@ | ||
import { fs } from 'memfs'; | ||
import { join } from 'path'; | ||
import { describe, expect, test, vi } from 'vitest'; | ||
import type { FsUpdates, UpdateAppOptions } from '../types'; | ||
import { mergeIntegrationDir } from './update-files'; | ||
|
||
vi.mock('node:fs', () => ({ | ||
default: fs, | ||
})); | ||
|
||
function setup() { | ||
const fakeSrcDir = 'srcDir'; | ||
createFakeFiles(fakeSrcDir); | ||
|
||
const fakeDestDir = 'destDir'; | ||
|
||
const fakeFileUpdates: FsUpdates = { | ||
files: [], | ||
installedDeps: {}, | ||
installedScripts: [], | ||
}; | ||
|
||
const fakeOpts: UpdateAppOptions = { | ||
rootDir: fakeDestDir, | ||
integration: 'integration', | ||
}; | ||
|
||
return { | ||
fakeSrcDir, | ||
fakeDestDir, | ||
fakeFileUpdates, | ||
fakeOpts, | ||
}; | ||
} | ||
|
||
describe('mergeIntegrationDir', () => { | ||
test('should merge integration directory', async () => { | ||
const { fakeSrcDir, fakeDestDir, fakeFileUpdates, fakeOpts } = setup(); | ||
|
||
await mergeIntegrationDir(fakeFileUpdates, fakeOpts, fakeSrcDir, fakeDestDir); | ||
|
||
const actualResults = fakeFileUpdates.files.map((f) => f.path); | ||
const expectedResult = ['destDir/fake.ts', 'destDir/package.json', 'destDir/src/global.css']; | ||
|
||
expect(actualResults).toEqual(expectedResult); | ||
}); | ||
|
||
test('should merge integration directory in a monorepo', async () => { | ||
const { fakeSrcDir, fakeDestDir, fakeFileUpdates, fakeOpts } = setup(); | ||
|
||
// Create a global file in the destination director | ||
const monorepoSubDir = join(fakeDestDir, 'apps', 'subpackage', 'src'); | ||
fs.mkdirSync(monorepoSubDir, { recursive: true }); | ||
fs.writeFileSync(join(monorepoSubDir, 'global.css'), '/* CSS */'); | ||
|
||
fakeOpts.outDir = 'apps/subpackage'; | ||
fakeOpts.installDeps = true; | ||
|
||
await mergeIntegrationDir(fakeFileUpdates, fakeOpts, fakeSrcDir, fakeDestDir); | ||
|
||
const actualResults = fakeFileUpdates.files.map((f) => f.path); | ||
const expectedResult = [ | ||
`destDir/apps/subpackage/fake.ts`, | ||
`destDir/package.json`, | ||
`destDir/apps/subpackage/src/global.css`, | ||
]; | ||
|
||
expect(actualResults).toEqual(expectedResult); | ||
|
||
const actualGlobalCssContent = fakeFileUpdates.files.find( | ||
(f) => f.path === expectedResult[2] | ||
)?.content; | ||
|
||
expect(actualGlobalCssContent).toBe('p{color: red}\n\n/* CSS */\n'); | ||
}); | ||
}); | ||
|
||
function createFakeFiles(dir: string) { | ||
// Create fake src files | ||
fs.mkdirSync(join(dir, 'src'), { recursive: true }); | ||
fs.writeFileSync(join(dir, 'fake.ts'), 'fake file'); | ||
fs.writeFileSync(join(dir, 'package.json'), '{"name": "fake"}'); | ||
fs.writeFileSync(join(dir, 'src', 'global.css'), 'p{color: red}'); | ||
} |
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
Oops, something went wrong.