-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonality): Adds
workspaces
property to project configuration (
#284)
- Loading branch information
1 parent
70dcda0
commit 0508b8f
Showing
21 changed files
with
194 additions
and
111 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,7 @@ | ||
--- | ||
"@commonalityco/data-project": patch | ||
"@commonalityco/utils-core": patch | ||
"commonality": patch | ||
--- | ||
|
||
Adds a `workspaces` property to the project configuration file. This will allow you to override your package manager's workspaces. This will also allow integrated monorepos to filter packages without adding a workspaces property to their package manager. |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { ProjectConfig } from '@commonalityco/utils-core'; | ||
import { ProjectConfigInput } from '@commonalityco/utils-core'; | ||
|
||
export function defineConfig(config: ProjectConfig): ProjectConfig { | ||
export function defineConfig(config: ProjectConfigInput): ProjectConfigInput { | ||
return config; | ||
} |
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
3 changes: 3 additions & 0 deletions
3
packages/data-project/test/fixtures/empty-configuration/commonality.config.ts
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 @@ | ||
import { defineConfig } from 'commonality'; | ||
|
||
export default defineConfig({}); |
5 changes: 5 additions & 0 deletions
5
packages/data-project/test/fixtures/empty-workspaces/commonality.config.ts
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 @@ | ||
import { defineConfig } from 'commonality'; | ||
|
||
export default defineConfig({ | ||
workspaces: [], | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/data-project/test/fixtures/explicit-workspaces/commonality.config.ts
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 @@ | ||
import { defineConfig } from 'commonality'; | ||
|
||
export default defineConfig({ | ||
workspaces: ['apps/**', 'packages/**'], | ||
}); |
4 changes: 2 additions & 2 deletions
4
packages/data-project/test/fixtures/npm-workspace/package.json
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"workspaces": [ | ||
"./packages/**", | ||
"./apps/**" | ||
"apps/**", | ||
"packages/**" | ||
] | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/data-project/test/fixtures/pnpm-workspace/pnpm-workspace.yaml
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
packages: | ||
- './packages/**' | ||
- './apps/**' | ||
- 'apps/**' | ||
- 'packages/**' |
4 changes: 2 additions & 2 deletions
4
packages/data-project/test/fixtures/yarn-workspace/package.json
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"workspaces": [ | ||
"./packages/**", | ||
"./apps/**" | ||
"apps/**", | ||
"packages/**" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,88 +1,97 @@ | ||
import { PackageManager } from '@commonalityco/utils-core'; | ||
import path from 'node:path'; | ||
import { getWorkspaceGlobs } from '../src/get-workspace-globs'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
describe('getWorkspaceGlobs', () => { | ||
describe('when run in an un-initialized project', () => { | ||
it('returns the default globs', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'uninitialized', | ||
); | ||
|
||
const config = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(config).toEqual(['./**']); | ||
test('returns default globs when there is no package manager workspaces or explicit workspaces configured', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'uninitialized', | ||
); | ||
|
||
const config = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.NPM, | ||
}); | ||
|
||
expect(config).toEqual(['./**']); | ||
}); | ||
|
||
test('returns the workspaces when set via project configuration', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'explicit-workspaces', | ||
); | ||
|
||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(['apps/**', 'packages/**']); | ||
}); | ||
|
||
test('returns the default globs when set to an empty array via project configuration', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'empty-workspaces', | ||
); | ||
|
||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(['./**']); | ||
}); | ||
|
||
describe('when run in an initialized project', () => { | ||
describe('when the workspace option exists', () => { | ||
const expectedWorkspaceGlobs = ['./packages/**', './apps/**']; | ||
|
||
it(`should return the correct globs for an NPM workspace`, async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'npm-workspace', | ||
); | ||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.NPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(expectedWorkspaceGlobs); | ||
}); | ||
|
||
it(`should return the correct globs for a Yarn workspace`, async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'yarn-workspace', | ||
); | ||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.YARN, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(expectedWorkspaceGlobs); | ||
}); | ||
|
||
it(`should return the correct globs for a pnpm workspace`, async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'pnpm-workspace', | ||
); | ||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(expectedWorkspaceGlobs); | ||
}); | ||
test('returns the workspaces when set with npm', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'npm-workspace', | ||
); | ||
|
||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.NPM, | ||
}); | ||
|
||
describe('when the workspace option does not exist', () => { | ||
it(`should return the default globs`, async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'missing-workspace-globs', | ||
); | ||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(['./**']); | ||
}); | ||
expect(workspaceGlobs).toEqual(['apps/**', 'packages/**']); | ||
}); | ||
|
||
test('returns the workspaces when set with yarn', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'yarn-workspace', | ||
); | ||
|
||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.YARN, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(['apps/**', 'packages/**']); | ||
}); | ||
|
||
test('returns the workspaces when set with pnpm', async () => { | ||
const rootDirectory = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'./fixtures', | ||
'pnpm-workspace', | ||
); | ||
|
||
const workspaceGlobs = await getWorkspaceGlobs({ | ||
rootDirectory, | ||
packageManager: PackageManager.PNPM, | ||
}); | ||
|
||
expect(workspaceGlobs).toEqual(['apps/**', 'packages/**']); | ||
}); | ||
}); |
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.