Skip to content

Commit

Permalink
Merge pull request #2391 from AlbertoBrusa/modular-ignore
Browse files Browse the repository at this point in the history
Modular respects .gitignore & .modularignore
  • Loading branch information
AlbertoBrusa authored May 19, 2023
2 parents 7a7c247 + 034cc29 commit a5a0372
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-bats-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'modular-scripts': major
'@modular-scripts/workspace-resolver': major
---

Modular's workspace resolver now ignores a workspace if covered by a
.modularignore or .gitignore (.modularignore overrides .gitignore)
Empty file added .modularignore
Empty file.
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ _e.g._
The `package.json#modular.type` can be `"root"`, `"app"`, `"view"`,
`"esm-view"`, `"source"`, `"template"` or `"package"`. Read more about Modular
types in [this explainer](/docs/package-types).

## `.modularignore` & `.gitignore`

Modular respects `.gitignore` when identifying workspaces in the repository,
ignoring any workspaces covered by the repo's `.gitignore`. This behavior can be
overridden by providing a `.modularignore`.
2 changes: 1 addition & 1 deletion packages/workspace-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"license": "Apache-2.0",
"main": "src/index.ts",
"dependencies": {
"@esm2cjs/globby": "13.1.4",
"fs-extra": "^10.1.0",
"globby": "11.1.0",
"semver": "7.3.7"
},
"devDependencies": {
Expand Down
33 changes: 25 additions & 8 deletions packages/workspace-resolver/src/resolve-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path, { join } from 'path';
import { readJson } from 'fs-extra';
import globby from 'globby';
import { existsSync, readJson } from 'fs-extra';
import { globbySync } from '@esm2cjs/globby';
import semver from 'semver';
import type {
ModularPackageJson,
Expand All @@ -17,26 +17,27 @@ function packageJsonPath(dir: string) {
}

function resolveWorkspacesDefinition(
cwd: string,
root: string,
def: ModularPackageJson['workspaces'],
ignoreFiles: string[],
): string[] {
if (!def) {
return [];
}

if (Array.isArray(def)) {
return def.flatMap((path: string) => {
return globby.sync(
return globbySync(
[`${path}/package.json`, '!**/node_modules/**/*', '!**/__tests__/**/*'],
{
absolute: false,
cwd,
cwd: root,
ignoreFiles: ignoreFiles,
},
);
});
}

return resolveWorkspacesDefinition(cwd, def.packages);
return resolveWorkspacesDefinition(root, def.packages, ignoreFiles);
}

function readPackageJson(
Expand Down Expand Up @@ -128,7 +129,23 @@ export async function resolveWorkspace(
}
}

for (const link of resolveWorkspacesDefinition(root, json.workspaces)) {
// Filter out workspaces covered by .modularignore or .gitignore
const ignoreFiles: string[] = [];

const modularIgnorePath = path.join(root, '.modularignore');
const gitIgnore = path.join(root, '.gitignore');

if (existsSync(modularIgnorePath)) {
ignoreFiles.push('.modularignore');
} else if (existsSync(gitIgnore)) {
ignoreFiles.push('.gitignore');
}

for (const link of resolveWorkspacesDefinition(
root,
json.workspaces,
ignoreFiles,
)) {
const [, child] = await resolveWorkspace(
link,
workingDirToUse,
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,22 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@esm2cjs/globby@13.1.4":
version "13.1.4"
resolved "https://registry.yarnpkg.com/@esm2cjs/globby/-/globby-13.1.4.tgz#38794c6b560654cb94e413b78ab568acf594bd6f"
integrity sha512-JES/VBjQfk78esAY7SSVk2c77v94UKVlOPPTP5HBFRjY5IIr0hjE6B3LzYzY98oaO9ygYVy5CURGdxasDVGv1g==
dependencies:
"@esm2cjs/slash" "^4.0.0"
dir-glob "^3.0.1"
fast-glob "^3.2.11"
ignore "^5.2.0"
merge2 "^1.4.1"

"@esm2cjs/slash@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@esm2cjs/slash/-/slash-4.0.0.tgz#5101e35a912eeb308c34f448c81cf353048d59b5"
integrity sha512-UUTg4pcAaq1D3R4yj0T+up/eBnZko6nE0ToBq6m6c0rHmpYPIGh/UrNMEeZV2hkLKpXBg6i1Zr9tJgmXq1T2BA==

"@floating-ui/core@^0.7.3":
version "0.7.3"
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-0.7.3.tgz#d274116678ffae87f6b60e90f88cc4083eefab86"
Expand Down

0 comments on commit a5a0372

Please sign in to comment.