-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
445799c
commit 7adf3a2
Showing
7 changed files
with
147 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type LinkConfig = { | ||
packages?: string[]; | ||
} |
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,19 @@ | ||
import type { LinkConfig } from '../types'; | ||
import { fsExists } from './fs-exists'; | ||
import { readJsonFile } from './read-json-file'; | ||
|
||
const configPath = 'link.config.json'; | ||
|
||
export async function loadConfig() { | ||
const configExists = await fsExists(configPath); | ||
|
||
if (!configExists) { | ||
return null; | ||
} | ||
|
||
try { | ||
return readJsonFile<LinkConfig>(configPath); | ||
} catch (error) { | ||
throw new Error(`Failed to parse config JSON: ${(error as any).message}`); | ||
} | ||
} |
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,62 @@ | ||
import path from 'path'; | ||
import { testSuite, expect } from 'manten'; | ||
import { execa, execaNode } from 'execa'; | ||
import { createFixture } from '../utils/create-fixture'; | ||
import { link } from '../utils/link'; | ||
|
||
export default testSuite(({ describe }, nodePath: string) => { | ||
describe('link.config.json', ({ test }) => { | ||
test('symlink', async () => { | ||
const fixture = await createFixture('./tests/fixtures/'); | ||
|
||
const entryPackagePath = path.join(fixture.path, 'package-entry'); | ||
|
||
await fixture.writeJson('package-entry/link.config.json', { | ||
packages: [ | ||
// Relative path & binary | ||
'../package-binary', | ||
|
||
// Absolute path | ||
path.join(fixture.path, 'package-files'), | ||
|
||
// Package with @org in name | ||
'../package-organization', | ||
], | ||
}); | ||
|
||
await link([], { | ||
cwd: entryPackagePath, | ||
nodePath, | ||
}); | ||
|
||
const packageA = await execaNode( | ||
path.join(entryPackagePath, 'index.js'), | ||
[], | ||
{ | ||
nodePath, | ||
nodeOptions: [], | ||
}, | ||
); | ||
expect(packageA.stdout).toBe('["package-entry","package-binary","package-files","@organization/package-organization"]'); | ||
|
||
// Executable via npm | ||
await fixture.writeJson('package-entry/package.json', { | ||
scripts: { | ||
test: 'binary', | ||
}, | ||
}); | ||
const binaryNpm = await execa('npm', ['test'], { | ||
cwd: entryPackagePath, | ||
}); | ||
expect(binaryNpm.stdout).toMatch('package-binary'); | ||
|
||
const binary = await execa(path.join(entryPackagePath, 'node_modules/.bin/binary')); | ||
expect(binary.stdout).toBe('package-binary'); | ||
|
||
const nonPublishFileExists = await fixture.exists('package-entry/node_modules/package-files/non-publish-file.js'); | ||
expect(nonPublishFileExists).toBe(true); | ||
|
||
await fixture.rm(); | ||
}); | ||
}); | ||
}); |