workspace-tools
Advanced tools
Comparing version 0.10.3 to 0.11.0
@@ -5,3 +5,18 @@ { | ||
{ | ||
"date": "Tue, 26 Jan 2021 09:28:29 GMT", | ||
"date": "Wed, 27 Jan 2021 20:58:44 GMT", | ||
"tag": "workspace-tools_v0.11.0", | ||
"version": "0.11.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"comment": "Adding NPM 7 Workspaces implementation.", | ||
"author": "fecamina@microsoft.com", | ||
"commit": "e04bbc030ff870b7b22c101f4948ff98c45ccf23", | ||
"package": "workspace-tools" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Tue, 26 Jan 2021 09:28:35 GMT", | ||
"tag": "workspace-tools_v0.10.3", | ||
@@ -8,0 +23,0 @@ "version": "0.10.3", |
# Change Log - workspace-tools | ||
This log was last generated on Tue, 26 Jan 2021 09:28:29 GMT and should not be manually modified. | ||
This log was last generated on Wed, 27 Jan 2021 20:58:44 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 0.11.0 | ||
Wed, 27 Jan 2021 20:58:44 GMT | ||
### Minor changes | ||
- Adding NPM 7 Workspaces implementation. (fecamina@microsoft.com) | ||
## 0.10.3 | ||
Tue, 26 Jan 2021 09:28:29 GMT | ||
Tue, 26 Jan 2021 09:28:35 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
@@ -7,2 +7,3 @@ "use strict"; | ||
const rush_1 = require("../workspaces/implementations/rush"); | ||
const npm_1 = require("../workspaces/implementations/npm"); | ||
describe("getYarnWorkspaceRoot()", () => { | ||
@@ -29,1 +30,8 @@ it("gets the root of the workspace", async () => { | ||
}); | ||
describe("getNpmWorkspaceRoot()", () => { | ||
it("gets the root of the workspace", async () => { | ||
const repoRoot = await setupFixture_1.setupFixture("monorepo-npm"); | ||
const workspaceRoot = npm_1.getNpmWorkspaceRoot(repoRoot); | ||
expect(workspaceRoot).toBe(repoRoot); | ||
}); | ||
}); |
@@ -11,2 +11,3 @@ "use strict"; | ||
const rush_1 = require("../workspaces/implementations/rush"); | ||
const npm_1 = require("../workspaces/implementations/npm"); | ||
describe("getYarnWorkspaces()", () => { | ||
@@ -60,1 +61,25 @@ it("gets the name and path of the workspaces", async () => { | ||
}); | ||
describe("getNpmWorkspaces()", () => { | ||
it("gets the name and path of the workspaces", async () => { | ||
const packageRoot = await setupFixture_1.setupFixture("monorepo-npm"); | ||
const workspacesPackageInfo = npm_1.getNpmWorkspaces(packageRoot); | ||
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a"); | ||
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b"); | ||
expect(workspacesPackageInfo).toMatchObject([ | ||
{ name: "package-a", path: packageAPath }, | ||
{ name: "package-b", path: packageBPath }, | ||
]); | ||
}); | ||
it("gets the name and path of the workspaces using the shorthand configuration", async () => { | ||
const packageRoot = await setupFixture_1.setupFixture("monorepo-shorthand"); | ||
const workspacesPackageInfo = npm_1.getNpmWorkspaces(packageRoot); | ||
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a"); | ||
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b"); | ||
const individualPath = path_1.default.join(packageRoot, "individual"); | ||
expect(workspacesPackageInfo).toMatchObject([ | ||
{ name: "package-a", path: packageAPath }, | ||
{ name: "package-b", path: packageBPath }, | ||
{ name: "individual", path: individualPath }, | ||
]); | ||
}); | ||
}); |
@@ -7,2 +7,3 @@ "use strict"; | ||
const rush_1 = require("./implementations/rush"); | ||
const npm_1 = require("./implementations/npm"); | ||
const workspaceGetter = { | ||
@@ -12,2 +13,3 @@ yarn: yarn_1.getYarnWorkspaceRoot, | ||
rush: rush_1.getRushWorkspaceRoot, | ||
npm: npm_1.getNpmWorkspaceRoot, | ||
}; | ||
@@ -14,0 +16,0 @@ const preferred = process.env |
@@ -7,2 +7,3 @@ "use strict"; | ||
const rush_1 = require("./implementations/rush"); | ||
const npm_1 = require("./implementations/npm"); | ||
const workspaceGetter = { | ||
@@ -12,2 +13,3 @@ yarn: yarn_1.getYarnWorkspaces, | ||
rush: rush_1.getRushWorkspaces, | ||
npm: npm_1.getNpmWorkspaces, | ||
}; | ||
@@ -14,0 +16,0 @@ const preferred = process.env |
@@ -1,2 +0,2 @@ | ||
export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush"; | ||
export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush" | "npm"; | ||
export declare function getWorkspaceImplementation(cwd: string): WorkspaceImplementations | undefined; |
@@ -20,3 +20,7 @@ "use strict"; | ||
} | ||
const npmLockPath = find_up_1.default.sync("package-lock.json", { cwd }); | ||
if (npmLockPath) { | ||
return "npm"; | ||
} | ||
} | ||
exports.getWorkspaceImplementation = getWorkspaceImplementation; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root")); | ||
const getPackagePaths_1 = require("../../getPackagePaths"); | ||
const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo"); | ||
const packageJsonWorkspaces_1 = require("./packageJsonWorkspaces"); | ||
function getYarnWorkspaceRoot(cwd) { | ||
const yarnWorkspacesRoot = find_yarn_workspace_root_1.default(cwd); | ||
const yarnWorkspacesRoot = packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot(cwd); | ||
if (!yarnWorkspacesRoot) { | ||
@@ -19,35 +12,6 @@ throw new Error("Could not find yarn workspaces root"); | ||
exports.getYarnWorkspaceRoot = getYarnWorkspaceRoot; | ||
function getRootPackageJson(yarnWorkspacesRoot) { | ||
const packageJsonFile = path_1.default.join(yarnWorkspacesRoot, "package.json"); | ||
try { | ||
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonFile, "utf-8")); | ||
return packageJson; | ||
} | ||
catch (e) { | ||
throw new Error("Could not load package.json from workspaces root"); | ||
} | ||
} | ||
function getPackages(packageJson) { | ||
const { workspaces } = packageJson; | ||
if (workspaces && Array.isArray(workspaces)) { | ||
return workspaces; | ||
} | ||
if (!workspaces || !workspaces.packages) { | ||
throw new Error("Could not find a workspaces object in package.json"); | ||
} | ||
return workspaces.packages; | ||
} | ||
function getYarnWorkspaces(cwd) { | ||
try { | ||
const yarnWorkspacesRoot = getYarnWorkspaceRoot(cwd); | ||
const rootPackageJson = getRootPackageJson(yarnWorkspacesRoot); | ||
const packages = getPackages(rootPackageJson); | ||
const packagePaths = getPackagePaths_1.getPackagePaths(yarnWorkspacesRoot, packages); | ||
const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths); | ||
return workspaceInfo; | ||
} | ||
catch (_a) { | ||
return []; | ||
} | ||
const yarnWorkspacesRoot = getYarnWorkspaceRoot(cwd); | ||
return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(yarnWorkspacesRoot); | ||
} | ||
exports.getYarnWorkspaces = getYarnWorkspaces; |
@@ -1,1 +0,1 @@ | ||
export declare type WorkspaceManager = "yarn" | "pnpm" | "rush"; | ||
export declare type WorkspaceManager = "yarn" | "pnpm" | "rush" | "npm"; |
{ | ||
"name": "workspace-tools", | ||
"version": "0.10.3", | ||
"version": "0.11.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98073
79
2278