jsii-rosetta 5.1.14-dev.0 → 5.1.14-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,11 @@ const os = require("node:os");
8
8
  const path = require("node:path");
9
9
  const fastGlob = require("fast-glob");
10
10
  const semver = require("semver");
11
- const semver_intersect_1 = require("semver-intersect");
12
11
  const find_utils_1 = require("./find-utils");
13
12
  const logging = require("./logging");
14
13
  const util_1 = require("./util");
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
15
+ const { intersect } = require('semver-intersect');
15
16
  /**
16
17
  * Collect the dependencies of a bunch of snippets together in one declaration
17
18
  *
@@ -145,7 +146,7 @@ function myVersionIntersect(a, b) {
145
146
  return a;
146
147
  }
147
148
  try {
148
- return (0, semver_intersect_1.intersect)(a, b);
149
+ return intersect(a, b);
149
150
  }
150
151
  catch (e) {
151
152
  throw new Error(`semver-intersect does not support either '${a}' or '${b}': ${e.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"snippet-dependencies.js","sourceRoot":"","sources":["../src/snippet-dependencies.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,qCAAiD;AACjD,8BAA8B;AAC9B,8BAA8B;AAC9B,kCAAkC;AAElC,sCAAsC;AACtC,iCAAiC;AACjC,uDAA6C;AAE7C,6CAAgF;AAChF,qCAAqC;AAErC,iCAAwD;AAExD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,QAA6B;IAC/D,MAAM,GAAG,GAA0C,EAAE,CAAC;IACtD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,uBAAuB,IAAI,EAAE,CAAC,EAAE;YAClF,GAAG,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,C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AAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,KAAK,SAAS,CAC3G,CAAC;IACF,IAAI,SAAS,EAAE;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QACpG,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE;YACpD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;SACrC;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,UAAU,CAAC,CAAwB;IAC1C,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;AAC/B,CAAC;AAED,SAAS,SAAS,CAAI,EAAU,EAAE,EAAU;IAC1C,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE;QAClB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KACX;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as cp from 'node:child_process';\nimport { promises as fsPromises } from 'node:fs';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson } from '@jsii/spec';\nimport * as fastGlob from 'fast-glob';\nimport * as semver from 'semver';\nimport { intersect } from 'semver-intersect';\n\nimport { findDependencyDirectory, findUp, isBuiltinModule } from './find-utils';\nimport * as logging from './logging';\nimport { TypeScriptSnippet, CompilationDependency } from './snippet';\nimport { mkDict, formatList, pathExists } from './util';\n\n/**\n * Collect the dependencies of a bunch of snippets together in one declaration\n *\n * We assume here the dependencies will not conflict.\n */\nexport function collectDependencies(snippets: TypeScriptSnippet[]) {\n const ret: Record<string, CompilationDependency> = {};\n for (const snippet of snippets) {\n for (const [name, source] of Object.entries(snippet.compilationDependencies ?? {})) {\n ret[name] = resolveConflict(name, source, ret[name]);\n }\n }\n return ret;\n}\n\n/**\n * Add transitive dependencies of concrete dependencies to the array\n *\n * This is necessary to prevent multiple copies of transitive dependencies on disk, which\n * jsii-based packages might not deal with very well.\n */\nexport async function expandWithTransitiveDependencies(deps: Record<string, CompilationDependency>) {\n const pathsSeen = new Set<string>();\n const queue = Object.values(deps).filter(isConcrete);\n\n let next = queue.shift();\n while (next) {\n await addDependenciesOf(next.resolvedDirectory);\n next = queue.shift();\n }\n\n async function addDependenciesOf(dir: string) {\n if (pathsSeen.has(dir)) {\n return;\n }\n pathsSeen.add(dir);\n try {\n const pj: PackageJson = JSON.parse(\n await fsPromises.readFile(path.join(dir, 'package.json'), { encoding: 'utf-8' }),\n );\n for (const [name, dep] of Object.entries(await resolveDependenciesFromPackageJson(pj, dir))) {\n if (!deps[name]) {\n deps[name] = dep;\n queue.push(dep);\n }\n }\n } catch (e: any) {\n if (e.code === 'ENOENT') {\n return;\n }\n throw e;\n }\n }\n}\n\n/**\n * Find the corresponding package directories for all dependencies in a package.json\n */\nexport async function resolveDependenciesFromPackageJson(packageJson: PackageJson | undefined, directory: string) {\n return mkDict(\n await Promise.all(\n Object.keys({ ...packageJson?.dependencies, ...packageJson?.peerDependencies })\n .filter((name) => !isBuiltinModule(name))\n .filter(\n (name) =>\n !packageJson?.bundledDependencies?.includes(name) && !packageJson?.bundleDependencies?.includes(name),\n )\n .map(\n async (name) =>\n [\n name,\n {\n type: 'concrete',\n resolvedDirectory: await fsPromises.realpath(await findDependencyDirectory(name, directory)),\n },\n ] as const,\n ),\n ),\n );\n}\n\nfunction resolveConflict(\n name: string,\n a: CompilationDependency,\n b: CompilationDependency | undefined,\n): CompilationDependency {\n if (!b) {\n return a;\n }\n\n if (a.type === 'concrete' && b.type === 'concrete') {\n if (b.resolvedDirectory !== a.resolvedDirectory) {\n throw new Error(`Dependency conflict: ${name} can be either ${a.resolvedDirectory} or ${b.resolvedDirectory}`);\n }\n return a;\n }\n\n if (a.type === 'symbolic' && b.type === 'symbolic') {\n // Intersect the ranges\n return {\n type: 'symbolic',\n versionRange: myVersionIntersect(a.versionRange, b.versionRange),\n };\n }\n\n if (a.type === 'concrete' && b.type === 'symbolic') {\n const concreteVersion: string = JSON.parse(\n fs.readFileSync(path.join(a.resolvedDirectory, 'package.json'), 'utf-8'),\n ).version;\n\n if (!semver.satisfies(concreteVersion, b.versionRange, { includePrerelease: true })) {\n throw new Error(\n `Dependency conflict: ${name} expected to match ${b.versionRange} but found ${concreteVersion} at ${a.resolvedDirectory}`,\n );\n }\n\n return a;\n }\n\n if (a.type === 'symbolic' && b.type === 'concrete') {\n // Reverse roles so we fall into the previous case\n return resolveConflict(name, b, a);\n }\n\n throw new Error('Cases should have been exhaustive');\n}\n\n/**\n * Check that the directory we were given has all the necessary dependencies in it\n *\n * It's a warning if this is not true, not an error.\n */\nexport async function validateAvailableDependencies(directory: string, deps: Record<string, CompilationDependency>) {\n logging.info(`Validating dependencies at ${directory}`);\n const failures = await Promise.all(\n Object.entries(deps).flatMap(async ([name, _dep]) => {\n try {\n await findDependencyDirectory(name, directory);\n return [];\n } catch {\n return [name];\n }\n }),\n );\n\n if (failures.length > 0) {\n logging.warn(\n `${directory}: packages necessary to compile examples missing from supplied directory: ${failures.join(', ')}`,\n );\n }\n}\n\n/**\n * Intersect two semver ranges\n *\n * The package we are using for this doesn't support all syntaxes yet.\n * Do some work on top.\n */\nfunction myVersionIntersect(a: string, b: string): string {\n if (a === '*') {\n return b;\n }\n if (b === '*') {\n return a;\n }\n\n try {\n return intersect(a, b);\n } catch (e: any) {\n throw new Error(`semver-intersect does not support either '${a}' or '${b}': ${e.message}`);\n }\n}\n\n/**\n * Prepare a temporary directory with symlinks to all the dependencies we need.\n *\n * - Symlinks the concrete dependencies\n * - Tries to first find the symbolic dependencies in a potential monorepo that might be present\n * (try both `lerna` and `yarn` monorepos).\n * - Installs the remaining symbolic dependencies using 'npm'.\n */\nexport async function prepareDependencyDirectory(deps: Record<string, CompilationDependency>): Promise<string> {\n const concreteDirs = Object.values(deps)\n .filter(isConcrete)\n .map((x) => x.resolvedDirectory);\n const monorepoPackages = await scanMonoRepos(concreteDirs);\n\n const tmpDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'rosetta'));\n logging.info(`Preparing dependency closure at ${tmpDir} (-vv for more details)`);\n\n // Resolved symbolic packages against monorepo\n const resolvedDeps = mkDict(\n Object.entries(deps).map(([name, dep]) => [\n name,\n dep.type === 'concrete'\n ? dep\n : ((monorepoPackages[name]\n ? { type: 'concrete', resolvedDirectory: monorepoPackages[name] }\n : dep) as CompilationDependency),\n ]),\n );\n\n const dependencies: Record<string, string> = {};\n for (const [name, dep] of Object.entries(resolvedDeps)) {\n if (isConcrete(dep)) {\n logging.debug(`${name} -> ${dep.resolvedDirectory}`);\n dependencies[name] = `file:${dep.resolvedDirectory}`;\n } else {\n logging.debug(`${name} @ ${dep.versionRange}`);\n dependencies[name] = dep.versionRange;\n }\n }\n\n await fsPromises.writeFile(\n path.join(tmpDir, 'package.json'),\n JSON.stringify(\n {\n name: 'examples',\n version: '0.0.1',\n private: true,\n dependencies,\n },\n undefined,\n 2,\n ),\n {\n encoding: 'utf-8',\n },\n );\n\n // Run NPM install on this package.json. We need to include --force for packages\n // that have a symbolic version in the symlinked dev tree (like \"0.0.0\"), but have\n // actual version range dependencies from externally installed packages (like \"^2.0.0\").\n cp.execSync(`npm install --force --loglevel error`, { cwd: tmpDir, encoding: 'utf-8' });\n\n return tmpDir;\n}\n\n/**\n * Map package name to directory\n */\nasync function scanMonoRepos(startingDirs: readonly string[]): Promise<Record<string, string>> {\n const globs = new Set<string>();\n for (const dir of startingDirs) {\n // eslint-disable-next-line no-await-in-loop\n setExtend(globs, await findMonoRepoGlobs(dir));\n }\n\n if (globs.size === 0) {\n return {};\n }\n\n logging.debug(`Monorepo package sources: ${Array.from(globs).join(', ')}`);\n\n const packageDirectories = await fastGlob(Array.from(globs).map(windowsToUnix), { onlyDirectories: true });\n const results = mkDict(\n (\n await Promise.all(\n packageDirectories.map(async (directory) => {\n const pjLocation = path.join(directory, 'package.json');\n return (await pathExists(pjLocation))\n ? [[JSON.parse(await fsPromises.readFile(pjLocation, 'utf-8')).name as string, directory] as const]\n : [];\n }),\n )\n ).flat(),\n );\n\n logging.debug(`Found ${Object.keys(results).length} packages in monorepo: ${formatList(Object.keys(results))}`);\n return results;\n}\n\nasync function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {\n const ret = new Set<string>();\n\n // Lerna monorepo\n const lernaJsonDir = await findUp(startingDir, async (dir) => pathExists(path.join(dir, 'lerna.json')));\n if (lernaJsonDir) {\n const lernaJson = JSON.parse(await fsPromises.readFile(path.join(lernaJsonDir, 'lerna.json'), 'utf-8'));\n for (const glob of lernaJson?.packages ?? []) {\n ret.add(path.join(lernaJsonDir, glob));\n }\n }\n\n // Yarn monorepo\n const yarnWsDir = await findUp(\n startingDir,\n async (dir) =>\n (await pathExists(path.join(dir, 'package.json'))) &&\n JSON.parse(await fsPromises.readFile(path.join(dir, 'package.json'), 'utf-8'))?.workspaces !== undefined,\n );\n if (yarnWsDir) {\n const yarnWs = JSON.parse(await fsPromises.readFile(path.join(yarnWsDir, 'package.json'), 'utf-8'));\n for (const glob of yarnWs.workspaces?.packages ?? []) {\n ret.add(path.join(yarnWsDir, glob));\n }\n }\n\n return ret;\n}\n\nfunction isConcrete(x: CompilationDependency): x is Extract<CompilationDependency, { type: 'concrete' }> {\n return x.type === 'concrete';\n}\n\nfunction setExtend<A>(xs: Set<A>, ys: Set<A>) {\n for (const y of ys) {\n xs.add(y);\n }\n return xs;\n}\n\n/**\n * Necessary for fastGlob\n */\nfunction windowsToUnix(x: string) {\n return x.replace(/\\\\/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CAAC,IAAI,KAAK,UAAU,CAAC;AAC/B,CAAC;AAED,SAAS,SAAS,CAAI,EAAU,EAAE,EAAU;IAC1C,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE;QAClB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KACX;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as cp from 'node:child_process';\nimport { promises as fsPromises } from 'node:fs';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { PackageJson } from '@jsii/spec';\nimport * as fastGlob from 'fast-glob';\nimport * as semver from 'semver';\n\nimport { findDependencyDirectory, findUp, isBuiltinModule } from './find-utils';\nimport * as logging from './logging';\nimport { TypeScriptSnippet, CompilationDependency } from './snippet';\nimport { mkDict, formatList, pathExists } from './util';\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst { intersect } = require('semver-intersect');\n\n/**\n * Collect the dependencies of a bunch of snippets together in one declaration\n *\n * We assume here the dependencies will not conflict.\n */\nexport function collectDependencies(snippets: TypeScriptSnippet[]) {\n const ret: Record<string, CompilationDependency> = {};\n for (const snippet of snippets) {\n for (const [name, source] of Object.entries(snippet.compilationDependencies ?? {})) {\n ret[name] = resolveConflict(name, source, ret[name]);\n }\n }\n return ret;\n}\n\n/**\n * Add transitive dependencies of concrete dependencies to the array\n *\n * This is necessary to prevent multiple copies of transitive dependencies on disk, which\n * jsii-based packages might not deal with very well.\n */\nexport async function expandWithTransitiveDependencies(deps: Record<string, CompilationDependency>) {\n const pathsSeen = new Set<string>();\n const queue = Object.values(deps).filter(isConcrete);\n\n let next = queue.shift();\n while (next) {\n await addDependenciesOf(next.resolvedDirectory);\n next = queue.shift();\n }\n\n async function addDependenciesOf(dir: string) {\n if (pathsSeen.has(dir)) {\n return;\n }\n pathsSeen.add(dir);\n try {\n const pj: PackageJson = JSON.parse(\n await fsPromises.readFile(path.join(dir, 'package.json'), { encoding: 'utf-8' }),\n );\n for (const [name, dep] of Object.entries(await resolveDependenciesFromPackageJson(pj, dir))) {\n if (!deps[name]) {\n deps[name] = dep;\n queue.push(dep);\n }\n }\n } catch (e: any) {\n if (e.code === 'ENOENT') {\n return;\n }\n throw e;\n }\n }\n}\n\n/**\n * Find the corresponding package directories for all dependencies in a package.json\n */\nexport async function resolveDependenciesFromPackageJson(packageJson: PackageJson | undefined, directory: string) {\n return mkDict(\n await Promise.all(\n Object.keys({ ...packageJson?.dependencies, ...packageJson?.peerDependencies })\n .filter((name) => !isBuiltinModule(name))\n .filter(\n (name) =>\n !packageJson?.bundledDependencies?.includes(name) && !packageJson?.bundleDependencies?.includes(name),\n )\n .map(\n async (name) =>\n [\n name,\n {\n type: 'concrete',\n resolvedDirectory: await fsPromises.realpath(await findDependencyDirectory(name, directory)),\n },\n ] as const,\n ),\n ),\n );\n}\n\nfunction resolveConflict(\n name: string,\n a: CompilationDependency,\n b: CompilationDependency | undefined,\n): CompilationDependency {\n if (!b) {\n return a;\n }\n\n if (a.type === 'concrete' && b.type === 'concrete') {\n if (b.resolvedDirectory !== a.resolvedDirectory) {\n throw new Error(`Dependency conflict: ${name} can be either ${a.resolvedDirectory} or ${b.resolvedDirectory}`);\n }\n return a;\n }\n\n if (a.type === 'symbolic' && b.type === 'symbolic') {\n // Intersect the ranges\n return {\n type: 'symbolic',\n versionRange: myVersionIntersect(a.versionRange, b.versionRange),\n };\n }\n\n if (a.type === 'concrete' && b.type === 'symbolic') {\n const concreteVersion: string = JSON.parse(\n fs.readFileSync(path.join(a.resolvedDirectory, 'package.json'), 'utf-8'),\n ).version;\n\n if (!semver.satisfies(concreteVersion, b.versionRange, { includePrerelease: true })) {\n throw new Error(\n `Dependency conflict: ${name} expected to match ${b.versionRange} but found ${concreteVersion} at ${a.resolvedDirectory}`,\n );\n }\n\n return a;\n }\n\n if (a.type === 'symbolic' && b.type === 'concrete') {\n // Reverse roles so we fall into the previous case\n return resolveConflict(name, b, a);\n }\n\n throw new Error('Cases should have been exhaustive');\n}\n\n/**\n * Check that the directory we were given has all the necessary dependencies in it\n *\n * It's a warning if this is not true, not an error.\n */\nexport async function validateAvailableDependencies(directory: string, deps: Record<string, CompilationDependency>) {\n logging.info(`Validating dependencies at ${directory}`);\n const failures = await Promise.all(\n Object.entries(deps).flatMap(async ([name, _dep]) => {\n try {\n await findDependencyDirectory(name, directory);\n return [];\n } catch {\n return [name];\n }\n }),\n );\n\n if (failures.length > 0) {\n logging.warn(\n `${directory}: packages necessary to compile examples missing from supplied directory: ${failures.join(', ')}`,\n );\n }\n}\n\n/**\n * Intersect two semver ranges\n *\n * The package we are using for this doesn't support all syntaxes yet.\n * Do some work on top.\n */\nfunction myVersionIntersect(a: string, b: string): string {\n if (a === '*') {\n return b;\n }\n if (b === '*') {\n return a;\n }\n\n try {\n return intersect(a, b);\n } catch (e: any) {\n throw new Error(`semver-intersect does not support either '${a}' or '${b}': ${e.message}`);\n }\n}\n\n/**\n * Prepare a temporary directory with symlinks to all the dependencies we need.\n *\n * - Symlinks the concrete dependencies\n * - Tries to first find the symbolic dependencies in a potential monorepo that might be present\n * (try both `lerna` and `yarn` monorepos).\n * - Installs the remaining symbolic dependencies using 'npm'.\n */\nexport async function prepareDependencyDirectory(deps: Record<string, CompilationDependency>): Promise<string> {\n const concreteDirs = Object.values(deps)\n .filter(isConcrete)\n .map((x) => x.resolvedDirectory);\n const monorepoPackages = await scanMonoRepos(concreteDirs);\n\n const tmpDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'rosetta'));\n logging.info(`Preparing dependency closure at ${tmpDir} (-vv for more details)`);\n\n // Resolved symbolic packages against monorepo\n const resolvedDeps = mkDict(\n Object.entries(deps).map(([name, dep]) => [\n name,\n dep.type === 'concrete'\n ? dep\n : ((monorepoPackages[name]\n ? { type: 'concrete', resolvedDirectory: monorepoPackages[name] }\n : dep) as CompilationDependency),\n ]),\n );\n\n const dependencies: Record<string, string> = {};\n for (const [name, dep] of Object.entries(resolvedDeps)) {\n if (isConcrete(dep)) {\n logging.debug(`${name} -> ${dep.resolvedDirectory}`);\n dependencies[name] = `file:${dep.resolvedDirectory}`;\n } else {\n logging.debug(`${name} @ ${dep.versionRange}`);\n dependencies[name] = dep.versionRange;\n }\n }\n\n await fsPromises.writeFile(\n path.join(tmpDir, 'package.json'),\n JSON.stringify(\n {\n name: 'examples',\n version: '0.0.1',\n private: true,\n dependencies,\n },\n undefined,\n 2,\n ),\n {\n encoding: 'utf-8',\n },\n );\n\n // Run NPM install on this package.json. We need to include --force for packages\n // that have a symbolic version in the symlinked dev tree (like \"0.0.0\"), but have\n // actual version range dependencies from externally installed packages (like \"^2.0.0\").\n cp.execSync(`npm install --force --loglevel error`, { cwd: tmpDir, encoding: 'utf-8' });\n\n return tmpDir;\n}\n\n/**\n * Map package name to directory\n */\nasync function scanMonoRepos(startingDirs: readonly string[]): Promise<Record<string, string>> {\n const globs = new Set<string>();\n for (const dir of startingDirs) {\n // eslint-disable-next-line no-await-in-loop\n setExtend(globs, await findMonoRepoGlobs(dir));\n }\n\n if (globs.size === 0) {\n return {};\n }\n\n logging.debug(`Monorepo package sources: ${Array.from(globs).join(', ')}`);\n\n const packageDirectories = await fastGlob(Array.from(globs).map(windowsToUnix), { onlyDirectories: true });\n const results = mkDict(\n (\n await Promise.all(\n packageDirectories.map(async (directory) => {\n const pjLocation = path.join(directory, 'package.json');\n return (await pathExists(pjLocation))\n ? [[JSON.parse(await fsPromises.readFile(pjLocation, 'utf-8')).name as string, directory] as const]\n : [];\n }),\n )\n ).flat(),\n );\n\n logging.debug(`Found ${Object.keys(results).length} packages in monorepo: ${formatList(Object.keys(results))}`);\n return results;\n}\n\nasync function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {\n const ret = new Set<string>();\n\n // Lerna monorepo\n const lernaJsonDir = await findUp(startingDir, async (dir) => pathExists(path.join(dir, 'lerna.json')));\n if (lernaJsonDir) {\n const lernaJson = JSON.parse(await fsPromises.readFile(path.join(lernaJsonDir, 'lerna.json'), 'utf-8'));\n for (const glob of lernaJson?.packages ?? []) {\n ret.add(path.join(lernaJsonDir, glob));\n }\n }\n\n // Yarn monorepo\n const yarnWsDir = await findUp(\n startingDir,\n async (dir) =>\n (await pathExists(path.join(dir, 'package.json'))) &&\n JSON.parse(await fsPromises.readFile(path.join(dir, 'package.json'), 'utf-8'))?.workspaces !== undefined,\n );\n if (yarnWsDir) {\n const yarnWs = JSON.parse(await fsPromises.readFile(path.join(yarnWsDir, 'package.json'), 'utf-8'));\n for (const glob of yarnWs.workspaces?.packages ?? []) {\n ret.add(path.join(yarnWsDir, glob));\n }\n }\n\n return ret;\n}\n\nfunction isConcrete(x: CompilationDependency): x is Extract<CompilationDependency, { type: 'concrete' }> {\n return x.type === 'concrete';\n}\n\nfunction setExtend<A>(xs: Set<A>, ys: Set<A>) {\n for (const y of ys) {\n xs.add(y);\n }\n return xs;\n}\n\n/**\n * Necessary for fastGlob\n */\nfunction windowsToUnix(x: string) {\n return x.replace(/\\\\/g, '/');\n}\n"]}
package/package.json CHANGED
@@ -23,6 +23,7 @@
23
23
  "test": "npx projen test",
24
24
  "test:watch": "npx projen test:watch",
25
25
  "upgrade": "npx projen upgrade",
26
+ "upgrade-jsii": "npx projen upgrade-jsii",
26
27
  "watch": "npx projen watch",
27
28
  "projen": "npx projen"
28
29
  },
@@ -34,34 +35,35 @@
34
35
  "devDependencies": {
35
36
  "@actions/core": "^1.10.1",
36
37
  "@actions/github": "^5.1.1",
37
- "@types/commonmark": "^0.27.7",
38
- "@types/jest": "^29.5.5",
39
- "@types/mock-fs": "^4.13.2",
38
+ "@types/commonmark": "^0.27.8",
39
+ "@types/jest": "^29.5.7",
40
+ "@types/mock-fs": "^4.13.3",
40
41
  "@types/node": "^16",
41
- "@types/stream-json": "^1.7.4",
42
- "@types/tar": "^6.1.6",
43
- "@types/workerpool": "^6.4.4",
42
+ "@types/stream-json": "^1.7.5",
43
+ "@types/tar": "^6.1.7",
44
+ "@types/workerpool": "^6.4.5",
44
45
  "@typescript-eslint/eslint-plugin": "^6",
45
46
  "@typescript-eslint/parser": "^6",
47
+ "constructs": "^10.0.0",
46
48
  "eslint": "^8",
47
49
  "eslint-config-prettier": "^8.10.0",
48
50
  "eslint-import-resolver-node": "^0.3.9",
49
51
  "eslint-import-resolver-typescript": "^3.6.1",
50
- "eslint-plugin-import": "^2.28.1",
52
+ "eslint-plugin-import": "^2.29.0",
51
53
  "eslint-plugin-prettier": "^4.2.1",
52
54
  "eslint-plugin-unicorn": "^46.0.1",
53
55
  "jest": "^29.7.0",
54
56
  "mock-fs": "^5.2.0",
55
57
  "npm-check-updates": "^16",
56
58
  "prettier": "^2.8.8",
57
- "projen": "^0.74.9",
59
+ "projen": "^0.76.15",
58
60
  "tar": "^6.2.0",
59
61
  "ts-jest": "^29.1.1",
60
62
  "ts-node": "^10.9.1"
61
63
  },
62
64
  "dependencies": {
63
- "@jsii/check-node": "1.90.0",
64
- "@jsii/spec": "^1.90.0",
65
+ "@jsii/check-node": "1.91.0",
66
+ "@jsii/spec": "^1.91.0",
65
67
  "@xmldom/xmldom": "^0.8.10",
66
68
  "chalk": "^4",
67
69
  "commonmark": "^0.30.0",
@@ -80,7 +82,7 @@
80
82
  "main": "lib/index.js",
81
83
  "license": "Apache-2.0",
82
84
  "homepage": "https://aws.github.io/jsii",
83
- "version": "5.1.14-dev.0",
85
+ "version": "5.1.14-dev.1",
84
86
  "types": "lib/index.d.ts",
85
87
  "exports": {
86
88
  ".": "./lib/index.js",
package/releases.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
- "current": "5.1",
2
+ "current": "5.2",
3
3
  "maintenance": {
4
+ "5.1": "2024-04-30T00:00:00.000Z",
4
5
  "5.0": "2024-01-31T00:00:00.000Z"
5
6
  },
6
7
  "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
@@ -1,13 +0,0 @@
1
- declare module 'semver-intersect' {
2
- /**
3
- * Computes the intersection between multiple semver ranges.
4
- *
5
- * @param ranges the ranges for which the intersection is requested.
6
- *
7
- * @returns the intersection of `ranges`.
8
- *
9
- * @throws Error if the intersection is empty.
10
- */
11
- function intersect(...ranges: string[]): string;
12
- }
13
- //# sourceMappingURL=semver-intersect.d.ts.map
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=semver-intersect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semver-intersect.js","sourceRoot":"","sources":["../../src/ambient/semver-intersect.ts"],"names":[],"mappings":"","sourcesContent":["/// Hand-written declaration for the semver-intersect module\ndeclare module 'semver-intersect' {\n /**\n * Computes the intersection between multiple semver ranges.\n *\n * @param ranges the ranges for which the intersection is requested.\n *\n * @returns the intersection of `ranges`.\n *\n * @throws Error if the intersection is empty.\n */\n function intersect(...ranges: string[]): string;\n}\n"]}