Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

workspace-tools

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workspace-tools - npm Package Compare versions

Comparing version 0.17.0 to 0.18.0

17

CHANGELOG.json

@@ -5,3 +5,18 @@ {

{
"date": "Thu, 02 Dec 2021 17:11:04 GMT",
"date": "Fri, 07 Jan 2022 00:04:25 GMT",
"tag": "workspace-tools_v0.18.0",
"version": "0.18.0",
"comments": {
"minor": [
{
"author": "kchau@microsoft.com",
"package": "workspace-tools",
"comment": "speed up workspace-tools - reducing weight and adding caches - lazy load pkg mgr helpers",
"commit": "6105a8eb81e4972b9ffbdd18669a137f0f5d9400"
}
]
}
},
{
"date": "Thu, 02 Dec 2021 17:11:12 GMT",
"tag": "workspace-tools_v0.17.0",

@@ -8,0 +23,0 @@ "version": "0.17.0",

# Change Log - workspace-tools
This log was last generated on Thu, 02 Dec 2021 17:11:04 GMT and should not be manually modified.
This log was last generated on Fri, 07 Jan 2022 00:04:25 GMT and should not be manually modified.
<!-- Start content -->
## 0.18.0
Fri, 07 Jan 2022 00:04:25 GMT
### Minor changes
- speed up workspace-tools - reducing weight and adding caches - lazy load pkg mgr helpers (kchau@microsoft.com)
## 0.17.0
Thu, 02 Dec 2021 17:11:04 GMT
Thu, 02 Dec 2021 17:11:12 GMT

@@ -11,0 +19,0 @@ ### Minor changes

36

lib/getPackagePaths.js

@@ -8,23 +8,23 @@ "use strict";

const globby_1 = __importDefault(require("globby"));
const packagePathsCache = {};
function getPackagePaths(workspacesRoot, packages) {
const packagePaths = packages.map((glob) => {
const globbed = globby_1.default
.sync(path_1.default.join(glob, "package.json").replace(/\\/g, "/"), {
cwd: workspacesRoot,
absolute: true,
ignore: ["**/node_modules/**"],
})
.map((p) => path_1.default.dirname(p));
return globbed;
});
/*
* fast-glob returns unix style path,
* so we use path.join to align the path with the platform.
*/
return packagePaths
.reduce((acc, cur) => {
return [...acc, ...cur];
if (packagePathsCache[workspacesRoot]) {
return packagePathsCache[workspacesRoot];
}
const packagePaths = globby_1.default
.sync(packages.map((glob) => path_1.default.join(glob, "package.json").replace(/\\/g, "/")), {
cwd: workspacesRoot,
absolute: true,
ignore: ["**/node_modules/**"],
stats: false,
})
.map((p) => path_1.default.join(p));
.map((p) => path_1.default.dirname(p));
if (path_1.default.sep === "/") {
packagePathsCache[workspacesRoot] = packagePaths;
}
else {
packagePathsCache[workspacesRoot] = packagePaths.map((p) => p.replace(/\//g, path_1.default.sep));
}
return packagePathsCache[workspacesRoot];
}
exports.getPackagePaths = getPackagePaths;

@@ -9,3 +9,2 @@ "use strict";

const fs_extra_1 = __importDefault(require("fs-extra"));
const fs_extra_2 = __importDefault(require("fs-extra"));
const tmp_1 = __importDefault(require("tmp"));

@@ -43,4 +42,4 @@ const git_1 = require("../git");

// a 'fixed' value for our tests, regardless of user configuration
git_1.gitFailFast(['symbolic-ref', 'HEAD', 'refs/heads/main'], { cwd });
git_1.gitFailFast(['config', 'init.defaultBranch', 'main'], { cwd });
git_1.gitFailFast(["symbolic-ref", "HEAD", "refs/heads/main"], { cwd });
git_1.gitFailFast(["config", "init.defaultBranch", "main"], { cwd });
git_1.stageAndCommit(["."], "test", cwd);

@@ -64,7 +63,7 @@ return cwd;

const pkgJsonPath = path_1.default.join(cwd, "package.json");
const pkgJson = fs_extra_2.default.readJSONSync(pkgJsonPath);
fs_extra_2.default.writeJSONSync(pkgJsonPath, Object.assign(Object.assign({}, pkgJson), { repository: {
url: remoteUrl
} }));
const pkgJson = JSON.parse(fs_extra_1.default.readFileSync(pkgJsonPath, "utf-8"));
fs_extra_1.default.writeFileSync(pkgJsonPath, JSON.stringify(Object.assign(Object.assign({}, pkgJson), { repository: {
url: remoteUrl,
} }), null, 2));
}
exports.setupLocalRemote = setupLocalRemote;

@@ -15,4 +15,3 @@ "use strict";

const find_up_1 = __importDefault(require("find-up"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const read_yaml_file_1 = __importDefault(require("read-yaml-file"));
const fs_1 = __importDefault(require("fs"));
const nameAtVersion_1 = require("./nameAtVersion");

@@ -31,3 +30,3 @@ exports.nameAtVersion = nameAtVersion_1.nameAtVersion;

const parseYarnLock = (await Promise.resolve().then(() => __importStar(require("@yarnpkg/lockfile")))).parse;
const yarnLock = fs_extra_1.default.readFileSync(yarnLockPath).toString();
const yarnLock = fs_1.default.readFileSync(yarnLockPath, 'utf-8');
const parsed = parseYarnLock(yarnLock);

@@ -43,3 +42,4 @@ memoization[yarnLockPath] = parsed;

}
const yaml = await read_yaml_file_1.default(pnpmLockPath);
const readYamlFile = require("read-yaml-file");
const yaml = (await readYamlFile(pnpmLockPath));
const parsed = parsePnpmLock_1.parsePnpmLock(yaml);

@@ -57,3 +57,3 @@ memoization[pnpmLockPath] = parsed;

try {
npmLockJson = fs_extra_1.default.readFileSync(npmLockPath);
npmLockJson = fs_1.default.readFileSync(npmLockPath, 'utf-8');
}

@@ -60,0 +60,0 @@ catch (_a) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const implementations_1 = require("./implementations");
const pnpm_1 = require("./implementations/pnpm");
const yarn_1 = require("./implementations/yarn");
const rush_1 = require("./implementations/rush");
const npm_1 = require("./implementations/npm");
const lerna_1 = require("./implementations/lerna");
const workspaceGetter = {
yarn: yarn_1.getYarnWorkspaceRoot,
pnpm: pnpm_1.getPnpmWorkspaceRoot,
rush: rush_1.getRushWorkspaceRoot,
npm: npm_1.getNpmWorkspaceRoot,
lerna: lerna_1.getLernaWorkspaceRoot,
};
const preferred = process.env
.PREFERRED_WORKSPACE_MANAGER;
const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
function getWorkspaceRoot(cwd) {
const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
if (!workspaceImplementation || !workspaceGetter[workspaceImplementation]) {
if (!workspaceImplementation) {
return;
}
return workspaceGetter[workspaceImplementation](cwd);
switch (workspaceImplementation) {
case "yarn":
return require(`./implementations/yarn`).getYarnWorkspaceRoot(cwd);
case "pnpm":
return require(`./implementations/pnpm`).getPnpmWorkspaceRoot(cwd);
case "rush":
return require(`./implementations/rush`).getRushWorkspaceRoot(cwd);
case "npm":
return require(`./implementations/npm`).getNpmWorkspaceRoot(cwd);
case "lerna":
return require(`./implementations/lerna`).getLernaWorkspaceRoot(cwd);
}
}
exports.getWorkspaceRoot = getWorkspaceRoot;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const implementations_1 = require("./implementations");
const lerna_1 = require("./implementations/lerna");
const npm_1 = require("./implementations/npm");
const pnpm_1 = require("./implementations/pnpm");
const rush_1 = require("./implementations/rush");
const yarn_1 = require("./implementations/yarn");
const workspaceGetter = {
yarn: yarn_1.getYarnWorkspaces,
pnpm: pnpm_1.getPnpmWorkspaces,
rush: rush_1.getRushWorkspaces,
npm: npm_1.getNpmWorkspaces,
lerna: lerna_1.getLernaWorkspaces,
};
const preferred = process.env
.PREFERRED_WORKSPACE_MANAGER;
const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
function getWorkspaces(cwd) {
const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
if (!workspaceImplementation || !workspaceGetter[workspaceImplementation]) {
if (!workspaceImplementation) {
return [];
}
return workspaceGetter[workspaceImplementation](cwd);
switch (workspaceImplementation) {
case "yarn":
return require(`./implementations/yarn`).getYarnWorkspaces(cwd);
case "pnpm":
return require(`./implementations/pnpm`).getPnpmWorkspaces(cwd);
case "rush":
return require(`./implementations/rush`).getRushWorkspaces(cwd);
case "npm":
return require(`./implementations/npm`).getNpmWorkspaces(cwd);
case "lerna":
return require(`./implementations/lerna`).getLernaWorkspaces(cwd);
}
}
exports.getWorkspaces = getWorkspaces;

@@ -1,2 +0,10 @@

export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush" | "npm" | 'lerna';
export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush" | "npm" | "lerna";
export interface ImplementationAndLockFile {
implementation: WorkspaceImplementations | undefined;
lockFile: string;
}
export declare function getWorkspaceImplementationAndLockFile(cwd: string): {
implementation: WorkspaceImplementations | undefined;
lockFile: string;
} | undefined;
export declare function getWorkspaceImplementation(cwd: string): WorkspaceImplementations | undefined;

@@ -7,26 +7,53 @@ "use strict";

const find_up_1 = __importDefault(require("find-up"));
function getWorkspaceImplementation(cwd) {
// This needs to come before Yarn and NPM because
// lerna can be used with either package manager
const lernaJsonPath = find_up_1.default.sync("lerna.json", { cwd });
if (lernaJsonPath) {
return "lerna";
const path_1 = __importDefault(require("path"));
const cache = {};
function getWorkspaceImplementationAndLockFile(cwd) {
if (cache[cwd]) {
return cache[cwd];
}
const yarnLockPath = find_up_1.default.sync("yarn.lock", { cwd });
if (yarnLockPath) {
return "yarn";
const lockFile = find_up_1.default.sync(["lerna.json", "yarn.lock", "pnpm-workspace.yaml", "rush.json", "package-lock.json"], {
cwd,
});
if (!lockFile) {
return;
}
const pnpmLockPath = find_up_1.default.sync("pnpm-workspace.yaml", { cwd });
if (pnpmLockPath) {
return "pnpm";
switch (path_1.default.basename(lockFile)) {
case "lerna.json":
cache[cwd] = {
implementation: "lerna",
lockFile,
};
break;
case "yarn.lock":
cache[cwd] = {
implementation: "yarn",
lockFile,
};
break;
case "pnpm-workspace.yaml":
cache[cwd] = {
implementation: "pnpm",
lockFile,
};
break;
case "rush.json":
cache[cwd] = {
implementation: "rush",
lockFile,
};
break;
case "package-lock.json":
cache[cwd] = {
implementation: "npm",
lockFile,
};
break;
}
const rushJsonPath = find_up_1.default.sync("rush.json", { cwd });
if (rushJsonPath) {
return "rush";
}
const npmLockPath = find_up_1.default.sync("package-lock.json", { cwd });
if (npmLockPath) {
return "npm";
}
return cache[cwd];
}
exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
function getWorkspaceImplementation(cwd) {
var _a;
return (_a = getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.implementation;
}
exports.getWorkspaceImplementation = getWorkspaceImplementation;

@@ -6,9 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const _1 = require(".");
const getPackagePaths_1 = require("../../getPackagePaths");
const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
function getPackageJsonWorkspaceRoot(cwd) {
const packageJsonWorkspacesRoot = find_yarn_workspace_root_1.default(cwd);
var _a;
const lockFile = (_a = _1.getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
const packageJsonWorkspacesRoot = lockFile ? path_1.default.dirname(lockFile) : cwd;
return packageJsonWorkspacesRoot;

@@ -15,0 +17,0 @@ }

@@ -8,3 +8,2 @@ "use strict";

const find_up_1 = __importDefault(require("find-up"));
const read_yaml_file_1 = require("read-yaml-file");
const getPackagePaths_1 = require("../../getPackagePaths");

@@ -24,3 +23,4 @@ const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");

const pnpmWorkspacesFile = path_1.default.join(pnpmWorkspacesRoot, "pnpm-workspace.yaml");
const pnpmWorkspaces = read_yaml_file_1.sync(pnpmWorkspacesFile);
const readYaml = require("read-yaml-file").sync;
const pnpmWorkspaces = readYaml(pnpmWorkspacesFile);
const packagePaths = getPackagePaths_1.getPackagePaths(pnpmWorkspacesRoot, pnpmWorkspaces.packages);

@@ -27,0 +27,0 @@ const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);

{
"name": "workspace-tools",
"version": "0.17.0",
"version": "0.18.0",
"license": "MIT",

@@ -22,4 +22,2 @@ "repository": {

"find-up": "^4.1.0",
"find-yarn-workspace-root": "^1.2.1",
"fs-extra": "^9.0.0",
"git-url-parse": "^11.1.2",

@@ -32,3 +30,2 @@ "globby": "^11.0.0",

"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@types/git-url-parse": "^9.0.0",

@@ -35,0 +32,0 @@ "@types/glob": "^7.1.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc