diff --git a/.projenrc.ts b/.projenrc.ts index 3502d0744..51d4d891d 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -468,23 +468,6 @@ const cxApi = overrideEslint( ////////////////////////////////////////////////////////////////////// -const yarnCling = configureProject( - new yarn.TypeScriptWorkspace({ - ...genericCdkProps({ - private: true, - }), - parent: repo, - name: '@aws-cdk/yarn-cling', - description: 'Tool for generating npm-shrinkwrap from yarn.lock', - srcdir: 'lib', - deps: ['@yarnpkg/lockfile', 'semver'], - devDeps: ['@types/semver', '@types/yarnpkg__lockfile'], - }), -); -yarnCling.testTask.prependExec('ln -sf ../../cdk test/test-fixture/jsii/node_modules/'); - -////////////////////////////////////////////////////////////////////// - const yargsGen = configureProject( new yarn.TypeScriptWorkspace({ ...genericCdkProps({ @@ -526,35 +509,6 @@ nodeBundle.eslint?.addRules({ 'no-console': ['off'] }); ////////////////////////////////////////////////////////////////////// -// This should be deprecated, but only after the move -const cdkBuildTools = configureProject( - new yarn.TypeScriptWorkspace({ - ...genericCdkProps({ - private: true, - }), - parent: repo, - name: '@aws-cdk/cdk-build-tools', - description: 'Build tools for CDK packages', - srcdir: 'lib', - deps: [ - yarnCling, - nodeBundle, - 'fs-extra@^9', - 'chalk@^4', - ], - devDeps: [ - '@types/fs-extra@^9', - ], - tsconfig: { - compilerOptions: { - esModuleInterop: false, - }, - }, - }), -); - -////////////////////////////////////////////////////////////////////// - // This should be deprecated, but only after the move const cliPluginContract = configureProject( new yarn.TypeScriptWorkspace({ @@ -696,7 +650,6 @@ const tmpToolkitHelpers = configureProject( name: '@aws-cdk/tmp-toolkit-helpers', description: 'A temporary package to hold code shared between aws-cdk and @aws-cdk/toolkit-lib', devDeps: [ - cdkBuildTools, '@types/archiver', '@types/semver', 'fast-check', @@ -743,9 +696,7 @@ const cli = configureProject( description: 'AWS CDK CLI, the command line tool for CDK apps', srcdir: 'lib', devDeps: [ - yarnCling, nodeBundle, - cdkBuildTools, yargsGen, cliPluginContract, tmpToolkitHelpers, @@ -1163,7 +1114,6 @@ const toolkitLib = configureProject( 'yargs@^15', ], devDeps: [ - cdkBuildTools, '@smithy/types', '@types/fs-extra', '@types/split2', diff --git a/aws-cdk-cli.code-workspace b/aws-cdk-cli.code-workspace index acae91b7e..2b9750d09 100644 --- a/aws-cdk-cli.code-workspace +++ b/aws-cdk-cli.code-workspace @@ -5,9 +5,6 @@ "path": ".", "name": "" }, - { - "path": "packages/@aws-cdk/cdk-build-tools" - }, { "path": "packages/@aws-cdk/cdk-cli-wrapper" }, @@ -35,9 +32,6 @@ { "path": "packages/@aws-cdk/user-input-gen" }, - { - "path": "packages/@aws-cdk/yarn-cling" - }, { "path": "packages/aws-cdk" }, diff --git a/package.json b/package.json index 90396c215..76c3d1dd4 100644 --- a/package.json +++ b/package.json @@ -60,10 +60,8 @@ "packages": [ "packages/@aws-cdk/cloud-assembly-schema", "packages/@aws-cdk/cloudformation-diff", - "packages/@aws-cdk/yarn-cling", "packages/@aws-cdk/user-input-gen", "packages/@aws-cdk/node-bundle", - "packages/@aws-cdk/cdk-build-tools", "packages/@aws-cdk/cli-plugin-contract", "packages/cdk-assets", "packages/@aws-cdk/tmp-toolkit-helpers", @@ -84,10 +82,8 @@ "projects": [ "/packages/@aws-cdk/cloud-assembly-schema", "/packages/@aws-cdk/cloudformation-diff", - "/packages/@aws-cdk/yarn-cling", "/packages/@aws-cdk/user-input-gen", "/packages/@aws-cdk/node-bundle", - "/packages/@aws-cdk/cdk-build-tools", "/packages/@aws-cdk/cli-plugin-contract", "/packages/cdk-assets", "/packages/@aws-cdk/tmp-toolkit-helpers", diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/.projen/deps.json b/packages/@aws-cdk/tmp-toolkit-helpers/.projen/deps.json index 5033e4172..1ab5e8add 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/.projen/deps.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/.projen/deps.json @@ -1,9 +1,5 @@ { "dependencies": [ - { - "name": "@aws-cdk/cdk-build-tools", - "type": "build" - }, { "name": "@cdklabs/eslint-plugin", "type": "build" diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/.projen/tasks.json b/packages/@aws-cdk/tmp-toolkit-helpers/.projen/tasks.json index b534ad6ab..6e3d82edd 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/.projen/tasks.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/.projen/tasks.json @@ -77,7 +77,7 @@ "name": "gather-versions", "steps": [ { - "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" @aws-cdk/tmp-toolkit-helpers MAJOR --deps @aws-cdk/cdk-build-tools", + "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" @aws-cdk/tmp-toolkit-helpers MAJOR --deps ", "receiveArgs": true } ] diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/package.json b/packages/@aws-cdk/tmp-toolkit-helpers/package.json index 1cc255a69..bf1da8251 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/package.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/package.json @@ -30,7 +30,6 @@ "organization": true }, "devDependencies": { - "@aws-cdk/cdk-build-tools": "^0.0.0", "@cdklabs/eslint-plugin": "^1.3.2", "@stylistic/eslint-plugin": "^3.1.0", "@types/archiver": "^6.0.3", diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.dev.json b/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.dev.json index 016dbb014..bc353830b 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.dev.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.dev.json @@ -35,9 +35,5 @@ "exclude": [ "node_modules" ], - "references": [ - { - "path": "../cdk-build-tools" - } - ] + "references": [] } diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.json b/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.json index 52c049e43..84f2e1f2b 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/tsconfig.json @@ -33,9 +33,5 @@ "src/**/*.ts" ], "exclude": [], - "references": [ - { - "path": "../cdk-build-tools" - } - ] + "references": [] } diff --git a/packages/@aws-cdk/toolkit-lib/.projen/deps.json b/packages/@aws-cdk/toolkit-lib/.projen/deps.json index afd06686b..413dca83c 100644 --- a/packages/@aws-cdk/toolkit-lib/.projen/deps.json +++ b/packages/@aws-cdk/toolkit-lib/.projen/deps.json @@ -1,9 +1,5 @@ { "dependencies": [ - { - "name": "@aws-cdk/cdk-build-tools", - "type": "build" - }, { "name": "@aws-cdk/tmp-toolkit-helpers", "type": "build" diff --git a/packages/@aws-cdk/toolkit-lib/.projen/tasks.json b/packages/@aws-cdk/toolkit-lib/.projen/tasks.json index 48e87c385..4ebb2b5ac 100644 --- a/packages/@aws-cdk/toolkit-lib/.projen/tasks.json +++ b/packages/@aws-cdk/toolkit-lib/.projen/tasks.json @@ -109,7 +109,7 @@ "name": "gather-versions", "steps": [ { - "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" @aws-cdk/toolkit-lib MAJOR --deps @aws-cdk/cloud-assembly-schema @aws-cdk/cloudformation-diff @aws-cdk/cdk-build-tools cdk-assets @aws-cdk/tmp-toolkit-helpers aws-cdk", + "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" @aws-cdk/toolkit-lib MAJOR --deps @aws-cdk/cloud-assembly-schema @aws-cdk/cloudformation-diff cdk-assets @aws-cdk/tmp-toolkit-helpers aws-cdk", "receiveArgs": true } ] diff --git a/packages/@aws-cdk/toolkit-lib/package.json b/packages/@aws-cdk/toolkit-lib/package.json index 1ec6692ad..5f0e37c1a 100644 --- a/packages/@aws-cdk/toolkit-lib/package.json +++ b/packages/@aws-cdk/toolkit-lib/package.json @@ -34,7 +34,6 @@ "organization": true }, "devDependencies": { - "@aws-cdk/cdk-build-tools": "^0.0.0", "@aws-cdk/tmp-toolkit-helpers": "^0.0.0", "@cdklabs/eslint-plugin": "^1.3.2", "@smithy/types": "^4.1.0", diff --git a/packages/@aws-cdk/toolkit-lib/tsconfig.dev.json b/packages/@aws-cdk/toolkit-lib/tsconfig.dev.json index 49a6cf38b..01c60489f 100644 --- a/packages/@aws-cdk/toolkit-lib/tsconfig.dev.json +++ b/packages/@aws-cdk/toolkit-lib/tsconfig.dev.json @@ -46,9 +46,6 @@ { "path": "../../cdk-assets" }, - { - "path": "../cdk-build-tools" - }, { "path": "../../aws-cdk" }, diff --git a/packages/@aws-cdk/toolkit-lib/tsconfig.json b/packages/@aws-cdk/toolkit-lib/tsconfig.json index 0b63f9637..58dfd0f1e 100644 --- a/packages/@aws-cdk/toolkit-lib/tsconfig.json +++ b/packages/@aws-cdk/toolkit-lib/tsconfig.json @@ -43,9 +43,6 @@ { "path": "../../cdk-assets" }, - { - "path": "../cdk-build-tools" - }, { "path": "../../aws-cdk" }, diff --git a/packages/@aws-cdk/yarn-cling/.eslintrc.js b/packages/@aws-cdk/yarn-cling/.eslintrc.js deleted file mode 100644 index 8f296a38a..000000000 --- a/packages/@aws-cdk/yarn-cling/.eslintrc.js +++ /dev/null @@ -1,9 +0,0 @@ -var path = require('path'); -var fs = require('fs'); -var contents = fs.readFileSync(`${__dirname}/.eslintrc.json`, { encoding: 'utf-8' }); -// Strip comments, JSON.parse() doesn't like those -contents = contents.replace(/^\/\/.*$/m, ''); -var json = JSON.parse(contents); -// Patch the .json config with something that can only be represented in JS -json.parserOptions.tsconfigRootDir = __dirname; -module.exports = json; \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/.eslintrc.json b/packages/@aws-cdk/yarn-cling/.eslintrc.json deleted file mode 100644 index 8d4b0afed..000000000 --- a/packages/@aws-cdk/yarn-cling/.eslintrc.json +++ /dev/null @@ -1,320 +0,0 @@ -// ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -{ - "env": { - "jest": true, - "node": true - }, - "root": true, - "plugins": [ - "@typescript-eslint", - "import", - "@cdklabs", - "@stylistic", - "jest", - "jsdoc" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", - "project": "./tsconfig.dev.json" - }, - "extends": [ - "plugin:import/typescript", - "plugin:jest/recommended", - "plugin:prettier/recommended" - ], - "settings": { - "import/parsers": { - "@typescript-eslint/parser": [ - ".ts", - ".tsx" - ] - }, - "import/resolver": { - "node": {}, - "typescript": { - "project": "./tsconfig.dev.json", - "alwaysTryTypes": true - } - } - }, - "ignorePatterns": [ - "*.js", - "*.d.ts", - "node_modules/", - "*.generated.ts", - "coverage", - "*.generated.ts" - ], - "rules": { - "@typescript-eslint/no-require-imports": [ - "error" - ], - "import/no-extraneous-dependencies": [ - "error", - { - "devDependencies": [ - "**/test/**", - "**/build-tools/**" - ], - "optionalDependencies": false, - "peerDependencies": true - } - ], - "import/no-unresolved": [ - "error" - ], - "import/order": [ - "error", - { - "groups": [ - "builtin", - "external" - ], - "alphabetize": { - "order": "asc", - "caseInsensitive": true - } - } - ], - "import/no-duplicates": "error", - "no-shadow": [ - "off" - ], - "@typescript-eslint/no-shadow": [ - "error" - ], - "key-spacing": [ - "error" - ], - "no-multiple-empty-lines": [ - "error", - { - "max": 1 - } - ], - "@typescript-eslint/no-floating-promises": [ - "error" - ], - "no-return-await": "off", - "@typescript-eslint/return-await": "error", - "no-trailing-spaces": [ - "error" - ], - "dot-notation": [ - "error" - ], - "no-bitwise": [ - "error" - ], - "@typescript-eslint/member-ordering": [ - "error", - { - "default": [ - "public-static-field", - "public-static-method", - "protected-static-field", - "protected-static-method", - "private-static-field", - "private-static-method", - "field", - "constructor", - "method" - ] - } - ], - "@cdklabs/no-core-construct": [ - "error" - ], - "@cdklabs/invalid-cfn-imports": [ - "error" - ], - "@cdklabs/no-literal-partition": [ - "error" - ], - "@cdklabs/no-invalid-path": [ - "error" - ], - "@cdklabs/promiseall-no-unbounded-parallelism": [ - "error" - ], - "no-throw-literal": [ - "error" - ], - "@stylistic/indent": [ - "error", - 2 - ], - "quotes": [ - "error", - "single", - { - "avoidEscape": true - } - ], - "@stylistic/member-delimiter-style": [ - "error" - ], - "@stylistic/comma-dangle": [ - "error", - "always-multiline" - ], - "@stylistic/no-extra-semi": [ - "error" - ], - "@stylistic/curly-newline": [ - "error", - "always" - ], - "comma-spacing": [ - "error", - { - "before": false, - "after": true - } - ], - "no-multi-spaces": [ - "error", - { - "ignoreEOLComments": false - } - ], - "array-bracket-spacing": [ - "error", - "never" - ], - "array-bracket-newline": [ - "error", - "consistent" - ], - "object-curly-spacing": [ - "error", - "always" - ], - "object-curly-newline": [ - "error", - { - "multiline": true, - "consistent": true - } - ], - "object-property-newline": [ - "error", - { - "allowAllPropertiesOnSameLine": true - } - ], - "keyword-spacing": [ - "error" - ], - "brace-style": [ - "error", - "1tbs", - { - "allowSingleLine": true - } - ], - "space-before-blocks": "error", - "curly": [ - "error", - "multi-line", - "consistent" - ], - "eol-last": [ - "error", - "always" - ], - "@stylistic/spaced-comment": [ - "error", - "always", - { - "exceptions": [ - "/", - "*" - ], - "markers": [ - "/" - ] - } - ], - "@stylistic/padded-blocks": [ - "error", - { - "classes": "never", - "blocks": "never", - "switches": "never" - } - ], - "jsdoc/require-param-description": [ - "error" - ], - "jsdoc/require-property-description": [ - "error" - ], - "jsdoc/require-returns-description": [ - "error" - ], - "jsdoc/check-alignment": [ - "error" - ], - "no-restricted-imports": [ - "error", - { - "paths": [ - { - "name": "punycode", - "message": "Package 'punycode' has to be imported with trailing slash, see warning in https://github.com/bestiejs/punycode.js#installation" - } - ], - "patterns": [ - "!punycode/" - ] - } - ], - "@typescript-eslint/consistent-type-imports": "error", - "semi": [ - "error", - "always" - ], - "quote-props": [ - "error", - "consistent-as-needed" - ], - "max-len": [ - "error", - { - "code": 150, - "ignoreUrls": true, - "ignoreStrings": true, - "ignoreTemplateLiterals": true, - "ignoreComments": true, - "ignoreRegExpLiterals": true - } - ], - "no-console": [ - "error" - ], - "no-restricted-syntax": [ - "error", - { - "selector": "CallExpression:matches([callee.name='createHash'], [callee.property.name='createHash']) Literal[value='md5']", - "message": "Use the md5hash() function from the core library if you want md5" - } - ], - "@typescript-eslint/unbound-method": "error", - "jest/expect-expect": "off", - "jest/no-conditional-expect": "off", - "jest/no-done-callback": "off", - "jest/no-standalone-expect": "off", - "jest/valid-expect": "off", - "jest/valid-title": "off", - "jest/no-identical-title": "off", - "jest/no-disabled-tests": "error", - "jest/no-focused-tests": "error", - "prettier/prettier": [ - "off" - ] - }, - "overrides": [] -} diff --git a/packages/@aws-cdk/yarn-cling/.gitattributes b/packages/@aws-cdk/yarn-cling/.gitattributes deleted file mode 100644 index c1b26c9d0..000000000 --- a/packages/@aws-cdk/yarn-cling/.gitattributes +++ /dev/null @@ -1,20 +0,0 @@ -# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". - -* text=auto eol=lf -/.eslintrc.js linguist-generated -/.eslintrc.json linguist-generated -/.gitattributes linguist-generated -/.gitignore linguist-generated -/.npmignore linguist-generated -/.prettierignore linguist-generated -/.prettierrc.json linguist-generated -/.projen/** linguist-generated -/.projen/deps.json linguist-generated -/.projen/files.json linguist-generated -/.projen/tasks.json linguist-generated -/jest.config.json linguist-generated -/LICENSE linguist-generated -/package.json linguist-generated -/tsconfig.dev.json linguist-generated -/tsconfig.json linguist-generated -/yarn.lock linguist-generated \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/.gitignore b/packages/@aws-cdk/yarn-cling/.gitignore deleted file mode 100644 index 50195572a..000000000 --- a/packages/@aws-cdk/yarn-cling/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -!/.gitattributes -!/.projen/tasks.json -!/.projen/deps.json -!/.projen/files.json -!/package.json -!/LICENSE -!/.npmignore -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json -pids -*.pid -*.seed -*.pid.lock -lib-cov -coverage -*.lcov -.nyc_output -build/Release -node_modules/ -jspm_packages/ -*.tsbuildinfo -.eslintcache -*.tgz -.yarn-integrity -.cache -!/jest.config.json -/coverage/ -!/.prettierignore -!/.prettierrc.json -!/test/ -!/tsconfig.json -!/tsconfig.dev.json -!/lib/ -/lib/**/*.js -/lib/**/*.d.ts -/lib/**/*.d.ts.map -/dist/ -!/.eslintrc.json -!/.eslintrc.js diff --git a/packages/@aws-cdk/yarn-cling/.npmignore b/packages/@aws-cdk/yarn-cling/.npmignore deleted file mode 100644 index b8c73a62c..000000000 --- a/packages/@aws-cdk/yarn-cling/.npmignore +++ /dev/null @@ -1,24 +0,0 @@ -# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -/.projen/ -/jest.config.json -/coverage/ -/.prettierignore -/.prettierrc.json -/test/ -/tsconfig.dev.json -!/lib/ -!/lib/**/*.js -!/lib/**/*.d.ts -dist -/tsconfig.json -/.github/ -/.vscode/ -/.idea/ -/.projenrc.js -tsconfig.tsbuildinfo -/.eslintrc.json -.eslintrc.js -*.ts -!*.d.ts -build-tools -/.gitattributes diff --git a/packages/@aws-cdk/yarn-cling/.prettierignore b/packages/@aws-cdk/yarn-cling/.prettierignore deleted file mode 100644 index b6999ad11..000000000 --- a/packages/@aws-cdk/yarn-cling/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -.eslintrc.js diff --git a/packages/@aws-cdk/yarn-cling/.prettierrc.json b/packages/@aws-cdk/yarn-cling/.prettierrc.json deleted file mode 100644 index af318ca5f..000000000 --- a/packages/@aws-cdk/yarn-cling/.prettierrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "printWidth": 120, - "singleQuote": true, - "trailingComma": "all", - "overrides": [] -} diff --git a/packages/@aws-cdk/yarn-cling/.projen/deps.json b/packages/@aws-cdk/yarn-cling/.projen/deps.json deleted file mode 100644 index e574343dc..000000000 --- a/packages/@aws-cdk/yarn-cling/.projen/deps.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "dependencies": [ - { - "name": "@cdklabs/eslint-plugin", - "type": "build" - }, - { - "name": "@stylistic/eslint-plugin", - "type": "build" - }, - { - "name": "@types/jest", - "type": "build" - }, - { - "name": "@types/node", - "version": "^16", - "type": "build" - }, - { - "name": "@types/semver", - "type": "build" - }, - { - "name": "@types/yarnpkg__lockfile", - "type": "build" - }, - { - "name": "@typescript-eslint/eslint-plugin", - "version": "^8", - "type": "build" - }, - { - "name": "@typescript-eslint/parser", - "version": "^8", - "type": "build" - }, - { - "name": "constructs", - "version": "^10.0.0", - "type": "build" - }, - { - "name": "eslint-config-prettier", - "type": "build" - }, - { - "name": "eslint-import-resolver-typescript", - "type": "build" - }, - { - "name": "eslint-plugin-import", - "type": "build" - }, - { - "name": "eslint-plugin-jest", - "type": "build" - }, - { - "name": "eslint-plugin-jsdoc", - "type": "build" - }, - { - "name": "eslint-plugin-prettier", - "type": "build" - }, - { - "name": "eslint", - "version": "^9", - "type": "build" - }, - { - "name": "jest", - "type": "build" - }, - { - "name": "jest-junit", - "version": "^16", - "type": "build" - }, - { - "name": "prettier", - "version": "^2.8", - "type": "build" - }, - { - "name": "projen", - "type": "build" - }, - { - "name": "ts-jest", - "type": "build" - }, - { - "name": "typescript", - "version": "5.6", - "type": "build" - }, - { - "name": "@yarnpkg/lockfile", - "type": "runtime" - }, - { - "name": "semver", - "type": "runtime" - } - ], - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." -} diff --git a/packages/@aws-cdk/yarn-cling/.projen/files.json b/packages/@aws-cdk/yarn-cling/.projen/files.json deleted file mode 100644 index 493bbd87e..000000000 --- a/packages/@aws-cdk/yarn-cling/.projen/files.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "files": [ - ".eslintrc.js", - ".eslintrc.json", - ".gitattributes", - ".gitignore", - ".npmignore", - ".prettierignore", - ".prettierrc.json", - ".projen/deps.json", - ".projen/files.json", - ".projen/tasks.json", - "jest.config.json", - "LICENSE", - "tsconfig.dev.json", - "tsconfig.json" - ], - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." -} diff --git a/packages/@aws-cdk/yarn-cling/.projen/tasks.json b/packages/@aws-cdk/yarn-cling/.projen/tasks.json deleted file mode 100644 index 8f750aec0..000000000 --- a/packages/@aws-cdk/yarn-cling/.projen/tasks.json +++ /dev/null @@ -1,172 +0,0 @@ -{ - "tasks": { - "build": { - "name": "build", - "description": "Full release build", - "steps": [ - { - "spawn": "pre-compile" - }, - { - "spawn": "compile" - }, - { - "spawn": "post-compile" - }, - { - "spawn": "test" - }, - { - "spawn": "package" - } - ] - }, - "bump": { - "name": "bump", - "description": "Bumps versions of local dependencies", - "steps": [ - { - "spawn": "gather-versions" - } - ] - }, - "check-for-updates": { - "name": "check-for-updates", - "env": { - "CI": "0" - }, - "steps": [ - { - "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --no-deprecated --dep=dev,peer,prod,optional --filter=@cdklabs/eslint-plugin,@stylistic/eslint-plugin,@types/jest,@types/semver,@types/yarnpkg__lockfile,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-jest,eslint-plugin-jsdoc,eslint-plugin-prettier,jest,projen,ts-jest,@yarnpkg/lockfile,semver" - } - ] - }, - "compile": { - "name": "compile", - "description": "Only compile", - "steps": [ - { - "exec": "tsc --build", - "receiveArgs": true - } - ] - }, - "default": { - "name": "default", - "description": "Synthesize project files", - "steps": [ - { - "exec": "cd ../../.. && npx projen default" - } - ] - }, - "eslint": { - "name": "eslint", - "description": "Runs eslint against the codebase", - "env": { - "ESLINT_USE_FLAT_CONFIG": "false" - }, - "steps": [ - { - "exec": "eslint --ext .ts,.tsx --fix --no-error-on-unmatched-pattern $@ lib test build-tools", - "receiveArgs": true - } - ] - }, - "gather-versions": { - "name": "gather-versions", - "steps": [ - { - "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" @aws-cdk/yarn-cling MAJOR --deps ", - "receiveArgs": true - } - ] - }, - "install": { - "name": "install", - "description": "Install project dependencies and update lockfile (non-frozen)", - "steps": [ - { - "exec": "yarn install --check-files" - } - ] - }, - "install:ci": { - "name": "install:ci", - "description": "Install project dependencies using frozen lockfile", - "steps": [ - { - "exec": "yarn install --check-files --frozen-lockfile" - } - ] - }, - "nx": { - "name": "nx", - "steps": [ - { - "exec": "nx run", - "receiveArgs": true - } - ] - }, - "package": { - "name": "package", - "description": "Creates the distribution package" - }, - "post-compile": { - "name": "post-compile", - "description": "Runs after successful compilation" - }, - "pre-compile": { - "name": "pre-compile", - "description": "Prepare the project for compilation" - }, - "test": { - "name": "test", - "description": "Run tests", - "steps": [ - { - "exec": "ln -sf ../../cdk test/test-fixture/jsii/node_modules/" - }, - { - "exec": "jest --passWithNoTests --updateSnapshot", - "receiveArgs": true - }, - { - "spawn": "eslint" - } - ] - }, - "test:watch": { - "name": "test:watch", - "description": "Run jest in watch mode", - "steps": [ - { - "exec": "jest --watch" - } - ] - }, - "unbump": { - "name": "unbump", - "description": "Resets versions of local dependencies to 0.0.0", - "steps": [ - { - "spawn": "gather-versions" - } - ] - }, - "watch": { - "name": "watch", - "description": "Watch & compile in the background", - "steps": [ - { - "exec": "tsc --build -w" - } - ] - } - }, - "env": { - "PATH": "$(npx -c \"node --print process.env.PATH\")" - }, - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." -} diff --git a/packages/@aws-cdk/yarn-cling/LICENSE b/packages/@aws-cdk/yarn-cling/LICENSE deleted file mode 100644 index d64569567..000000000 --- a/packages/@aws-cdk/yarn-cling/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/packages/@aws-cdk/yarn-cling/NOTICE b/packages/@aws-cdk/yarn-cling/NOTICE deleted file mode 100644 index cd0946c1c..000000000 --- a/packages/@aws-cdk/yarn-cling/NOTICE +++ /dev/null @@ -1,2 +0,0 @@ -AWS Cloud Development Kit (AWS CDK) -Copyright 2018-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/yarn-cling/README.md b/packages/@aws-cdk/yarn-cling/README.md deleted file mode 100644 index a89fcb712..000000000 --- a/packages/@aws-cdk/yarn-cling/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# yarn-cling - -Generate an NPM shrinkwrap file from a yarn-managed monorepo. - -## Why do we need an NPM shrinkwrap file? - -When vending JavaScript applications that are installed via NPM, an -`npm-shrinkwrap.json` is necessary to control the dependency tree of the -installed application, ensuring that all the dependencies have the -version that the application vendor expects. - -1. This prevents `npm install ` on the user's computer - from installing an untested combination of versions, one that may potentially - be broken. This *shouldn't* happen if everyone nicely keeps to semantic - versioning, but doing so relies on good intentions. - -2. Since most package's dependencies are written like `^1.2.0`, any application - in the NPM ecosystem can potentially be compromised by someone releasing a - minor or patch version of a library somewhere deep in the dependency tree - with malware in it. All subsequent `npm install `s would happily - install the new version of the now compromised library. - -The only way around both of these issues is an `npm-shrinkwrap.json`, which will -be respected by NPM on doing `npm install` (unlike `package-lock.json`, which -won't). - -Note that yarn doesn't support shrinkwrapping at all. We can't help those -people, but we can at least protect NPM users and tell people to use NPM to -install our applications if they want to have some semblance of installation -safety. - -## Okay fine. Why does this tool need to exist? - -There doesn't seem to be any existing tool that can generate the -`npm-shrinkwrap.json` file from our monorepo. - -### What about 'npm shrinkwrap' ? - -There is the command `npm shrinkwrap`. From various Googles, this command -varyingly used to accept arguments and not accept arguments. Its current -incarnation on my NPM (6.11.3) does not accept arguments, and simply -renames `package-lock.json => npm-shrinkwrap.json`. We don't have -a `package-lock.json` (because we manage our monorepo completely using -Yarn), so that obviously won't work. - -Nevertheless, if I run `npm shrinkwrap` a file IS generated. This file -contains SOME version information, but doesn't contain package integrity -checksums and breaks NPM when a subsequent `npm install` is run. NPM -exits with `npm ERR! Cannot read property 'match' of undefined`. - -### What about 'synp' ? - -There is a tool called synp which can convert `yarn.lock` to `package-lock.json` -(which is the same format as `npm-shrinkwrap.json`). - -Unfortunately, we only have one `yarn.lock` for the whole monorepo, whereas we -would need the subset of dependencies `yarn.lock` that apply to the application -we're trying to bundle. - -This tool does some inspired borrowing from `synp` but is monorepo-aware. - -## How does it work? - -Requires the monorepo dependency tree to have been bootstrapped, so that -we can look at the concrete `node_modules` directories of all packages involved -(because we need each package's `package.json` to separate production dependencies -from devDependencies). - -For all (production) dependencies of the package we're shrinkwrapping: - -- If the dependency is in `yarn.lock`, yarn resolved the version for us and - we copy that entry into the package lock file. -- If the dependency is not in `yarn.lock`, the dependency comes from the monorepo - and will be released at the same time as the current package. Unfortunately, - since it hasn't been downloaded yet we won't have an integrity for it. We simply - add an entry that contains the version number to the package lock. - -Recurse from the dependency's package directory. \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/bin/yarn-cling b/packages/@aws-cdk/yarn-cling/bin/yarn-cling deleted file mode 100755 index f5e2c6552..000000000 --- a/packages/@aws-cdk/yarn-cling/bin/yarn-cling +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('./yarn-cling.js'); \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/bin/yarn-cling.ts b/packages/@aws-cdk/yarn-cling/bin/yarn-cling.ts deleted file mode 100644 index 78d0777a0..000000000 --- a/packages/@aws-cdk/yarn-cling/bin/yarn-cling.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { generateShrinkwrap } from '../lib'; - -async function main() { - // No arguments, just assume current directory - await generateShrinkwrap({ - packageJsonFile: 'package.json', - outputFile: 'npm-shrinkwrap.json', - }); - - // eslint-disable-next-line no-console - console.error('Generated npm-shrinkwrap.json'); -} - -main().catch(e => { - // eslint-disable-next-line no-console - console.error(e); - process.exitCode = 1; -}); \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/jest.config.json b/packages/@aws-cdk/yarn-cling/jest.config.json deleted file mode 100644 index 0304b3297..000000000 --- a/packages/@aws-cdk/yarn-cling/jest.config.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "coverageProvider": "v8", - "moduleFileExtensions": [ - "ts", - "js" - ], - "maxWorkers": "80%", - "testEnvironment": "node", - "coverageThreshold": { - "global": { - "statements": 80, - "branches": 80, - "functions": 80, - "lines": 80 - } - }, - "collectCoverage": true, - "coverageReporters": [ - "text-summary", - "cobertura", - [ - "html", - { - "subdir": "html-report" - } - ] - ], - "testMatch": [ - "/test/**/?(*.)+(test).ts", - "/@(lib|test)/**/*(*.)@(spec|test).ts?(x)", - "/@(lib|test)/**/__tests__/**/*.ts?(x)" - ], - "coveragePathIgnorePatterns": [ - "\\.generated\\.[jt]s$", - "/test/", - ".warnings.jsii.js$", - "/node_modules/" - ], - "reporters": [ - "default", - [ - "jest-junit", - { - "suiteName": "jest tests", - "outputDirectory": "coverage" - } - ] - ], - "randomize": true, - "clearMocks": true, - "coverageDirectory": "coverage", - "testPathIgnorePatterns": [ - "/node_modules/" - ], - "watchPathIgnorePatterns": [ - "/node_modules/" - ], - "transform": { - "^.+\\.[t]sx?$": [ - "ts-jest", - { - "tsconfig": "tsconfig.dev.json" - } - ] - }, - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." -} diff --git a/packages/@aws-cdk/yarn-cling/lib/hoisting.ts b/packages/@aws-cdk/yarn-cling/lib/hoisting.ts deleted file mode 100644 index 9d6393949..000000000 --- a/packages/@aws-cdk/yarn-cling/lib/hoisting.ts +++ /dev/null @@ -1,163 +0,0 @@ -import type { PackageLockPackage } from './types'; - -/** - * Hoist package-lock dependencies in-place - * - * This happens in two phases: - * - * 1) Move every package into the parent scope (as long as it introduces no conflicts). - * This step mutates the dependency tree. - * 2) Once no more packages can be moved up, clean up the tree. This step mutates the - * tree declarations but cannot change versions of required packages. Two cleanups: - * 2a) Remove duplicates down the tree (same version that is inherited from above) - * 2b) Remove useless packages that aren't depended upon by anything in that subtree. - * To determine whether a package is useful or useless in a tree, we record - * each package's original dependencies before we start messing around in the - * tree. - * - * This two-phase process replaces a proces that did move-and-delete as one step, which - * sometimes would hoist a package into a place that was previously vacated by a conflicting - * version, thereby causing the wrong version to be loaded. - * - * Hoisting is still rather expensive on a large tree (~100ms), we should find ways to - * speed it up. - */ -export function hoistDependencies(packageTree: PackageLockPackage) { - const originalDependencies = new Map(); - recordOriginalDependencies(packageTree); - - moveUp(packageTree); - removeDupes(packageTree, []); - removeUseless(packageTree); - - // Move the children of the parent onto the same level if there are no conflicts - function moveUp(node: PackageLockPackage, parent?: PackageLockPackage) { - if (!node.dependencies) { - return; - } - - // Recurse - for (const child of Object.values(node.dependencies)) { - moveUp(child, node); - } - - // Then push packages from the current node into its parent - if (parent) { - for (const [depName, depPackage] of Object.entries(node.dependencies)) { - if (!parent.dependencies?.[depName]) { - // It's new and there's no version conflict, we can move it up. - parent.dependencies![depName] = depPackage; - } - } - } - } - - function removeDupes(node: PackageLockPackage, rootPath: Array) { - if (!node.dependencies) { - return; - } - - // Any dependencies here that are the same in the parent can be removed - for (const [depName, depPackage] of Object.entries(node.dependencies)) { - if (findInheritedDepVersion(depName, rootPath) === depPackage.version) { - delete node.dependencies[depName]; - } - } - - // Recurse - for (const child of Object.values(node.dependencies)) { - removeDupes(child, [node, ...rootPath]); - } - } - - function removeUseless(node: PackageLockPackage) { - if (!node.dependencies) { - return; - } - for (const [depName, depPkg] of Object.entries(node.dependencies)) { - if (!necessaryInTree(depName, depPkg.version, node)) { - delete node.dependencies[depName]; - } - } - - // Recurse - for (const child of Object.values(node.dependencies)) { - removeUseless(child); - } - - // If we ended up with empty dependencies, just get rid of the key (for clean printing) - if (Object.keys(node.dependencies).length === 0) { - delete node.dependencies; - } - } - - function findInheritedDepVersion(name: string, parentDependenciesChain: Array) { - for (const deps of parentDependenciesChain) { - if (deps.dependencies?.[name]) { - return deps.dependencies[name].version; - } - } - return undefined; - } - - function recordOriginalDependencies(node: PackageLockPackage) { - if (!node.dependencies) { - return; - } - - let list = originalDependencies.get(node); - if (!list) { - list = []; - originalDependencies.set(node, list); - } - - for (const [depName, depPkg] of Object.entries(node.dependencies)) { - list.push(`${depName}@${depPkg.version}`); - recordOriginalDependencies(depPkg); - } - } - - function necessaryInTree(name: string, version: string, tree: PackageLockPackage) { - if (originalDependencies.get(tree)?.includes(`${name}@${version}`)) { - return true; - } - if (!tree.dependencies) { - return false; - } - - for (const depPackage of Object.values(tree.dependencies)) { - if (necessaryInTree(name, version, depPackage)) { - return true; - } - } - return false; - } -} - -export function renderTree(tree: PackageLockPackage): string[] { - const ret = new Array(); - recurse(tree.dependencies ?? {}, []); - return ret.sort(compareSplit); - - function recurse(n: Record, parts: string[]) { - for (const [k, v] of Object.entries(n)) { - ret.push([...parts, k].join('.') + '=' + v.version); - recurse(v.dependencies ?? {}, [...parts, k]); - } - } - - function compareSplit(a: string, b: string): number { - // Sort so that: 'a=1', 'a.b=2' get sorted in that order. - const as = a.split(/\.|=/g); - const bs = b.split(/\.|=/g); - - for (let i = 0; i < as.length && i < bs.length; i++) { - const cmp = as[i].localeCompare(bs[i]); - if (cmp !== 0) { - return cmp; - } - } - - return as.length - bs.length; - } -} diff --git a/packages/@aws-cdk/yarn-cling/lib/index.ts b/packages/@aws-cdk/yarn-cling/lib/index.ts deleted file mode 100644 index 24f022378..000000000 --- a/packages/@aws-cdk/yarn-cling/lib/index.ts +++ /dev/null @@ -1,333 +0,0 @@ -import { promises as fs, exists } from 'fs'; -import * as path from 'path'; -import * as lockfile from '@yarnpkg/lockfile'; -import * as semver from 'semver'; -import { hoistDependencies } from './hoisting'; -import type { PackageJson, PackageLock, PackageLockEntry, PackageLockPackage, YarnLock } from './types'; - -export interface ShrinkwrapOptions { - /** - * The package.json file to start scanning for dependencies - */ - packageJsonFile: string; - - /** - * The output lockfile to generate - * - * @default - Don't generate the file, just return the calculated output - */ - outputFile?: string; - - /** - * Whether to hoist dependencies - * - * @default true - */ - hoist?: boolean; -} - -export async function generateShrinkwrap(options: ShrinkwrapOptions): Promise { - // No args (yet) - const packageJsonFile = options.packageJsonFile; - const packageJsonDir = path.dirname(packageJsonFile); - - const yarnLockLoc = await findYarnLock(packageJsonDir); - const yarnLock: YarnLock = lockfile.parse(await fs.readFile(yarnLockLoc, { encoding: 'utf8' })); - const pkgJson = await loadPackageJson(packageJsonFile); - - const lock = await generateLockFile(pkgJson, yarnLock, packageJsonDir); - - if (options.hoist ?? true) { - hoistDependencies({ version: '*', dependencies: lock.dependencies }); - } - - validateTree(lock); - - if (options.outputFile) { - // Write the shrinkwrap file - await fs.writeFile(options.outputFile, JSON.stringify(lock, undefined, 2), { encoding: 'utf8' }); - } - - return lock; -} - -async function generateLockFile(pkgJson: PackageJson, yarnLock: YarnLock, rootDir: string): Promise { - const lockFile = { - name: pkgJson.name, - version: pkgJson.version, - lockfileVersion: 1, - requires: true, - dependencies: await dependenciesFor(pkgJson.dependencies || {}, yarnLock, rootDir, [pkgJson.name]), - }; - - checkRequiredVersions(lockFile); - - return lockFile; -} - -const CYCLES_REPORTED = new Set(); - -// eslint-disable-next-line max-len -async function dependenciesFor(deps: Record, yarnLock: YarnLock, rootDir: string, dependencyPath: string[]): Promise> { - const ret: Record = {}; - - // Get rid of any monorepo symlinks - rootDir = await fs.realpath(rootDir); - - for (const [depName, versionRange] of Object.entries(deps)) { - if (dependencyPath.includes(depName)) { - const index = dependencyPath.indexOf(depName); - const beforeCycle = dependencyPath.slice(0, index); - const inCycle = [...dependencyPath.slice(index), depName]; - const cycleString = inCycle.join(' => '); - if (!CYCLES_REPORTED.has(cycleString)) { - // eslint-disable-next-line no-console - console.warn(`Dependency cycle: ${beforeCycle.join(' => ')} => [ ${cycleString} ]. Dropping dependency '${inCycle.slice(-2).join(' => ')}'.`); - CYCLES_REPORTED.add(cycleString); - } - continue; - } - - const depDir = await findPackageDir(depName, rootDir); - const depPkgJsonFile = path.join(depDir, 'package.json'); - const depPkgJson = await loadPackageJson(depPkgJsonFile); - const yarnKey = `${depName}@${versionRange}`; - - // Sanity check - if (depPkgJson.name !== depName) { - throw new Error(`Looking for '${depName}' from ${rootDir}, but found '${depPkgJson.name}' in ${depDir}`); - } - - const yarnResolved = yarnLock.object[yarnKey]; - if (yarnResolved) { - // Resolved by Yarn - ret[depName] = { - version: yarnResolved.version, - integrity: yarnResolved.integrity, - resolved: yarnResolved.resolved, - requires: depPkgJson.dependencies, - dependencies: await dependenciesFor(depPkgJson.dependencies || {}, yarnLock, depDir, [...dependencyPath, depName]), - }; - } else { - // Comes from monorepo, just use whatever's in package.json - ret[depName] = { - version: depPkgJson.version, - requires: depPkgJson.dependencies, - dependencies: await dependenciesFor(depPkgJson.dependencies || {}, yarnLock, depDir, [...dependencyPath, depName]), - }; - } - - // Simplify by removing useless entries - if (Object.keys(ret[depName].requires ?? {}).length === 0) { - delete ret[depName].requires; - } - if (Object.keys(ret[depName].dependencies ?? {}).length === 0) { - delete ret[depName].dependencies; - } - } - - return ret; -} - -async function findYarnLock(start: string) { - return findUp('yarn.lock', start); -} - -async function findUp(fileName: string, start: string) { - start = path.resolve(start); - let dir = start; - const yarnLockHere = () => path.join(dir, fileName); - while (!await fileExists(yarnLockHere())) { - const parent = path.dirname(dir); - if (parent === dir) { - throw new Error(`No ${fileName} found upwards from ${start}`); - } - dir = parent; - } - - return yarnLockHere(); -} - -async function loadPackageJson(fileName: string): Promise { - return JSON.parse(await fs.readFile(fileName, { encoding: 'utf8' })); -} - -async function fileExists(fullPath: string): Promise { - try { - await fs.stat(fullPath); - return true; - } catch (e: any) { - if (e.code === 'ENOENT' || e.code === 'ENOTDIR') { - return false; - } - throw e; - } -} - -export function formatPackageLock(entry: PackageLockEntry) { - const lines = new Array(); - recurse([], entry); - return lines.join('\n'); - - function recurse(names: string[], thisEntry: PackageLockEntry) { - if (names.length > 0) { - // eslint-disable-next-line no-console - lines.push(`${names.join(' -> ')} @ ${thisEntry.version}`); - } - for (const [depName, depEntry] of Object.entries(thisEntry.dependencies || {})) { - recurse([...names, depName], depEntry); - } - } -} - -/** - * Find package directory - * - * Do this by walking upwards in the directory tree until we find - * `/node_modules//package.json`. - * - * ------- - * - * Things that we tried but don't work: - * - * 1. require.resolve(`${depName}/package.json`, { paths: [rootDir] }); - * - * Breaks with ES Modules if `package.json` has not been exported, which is - * being enforced starting Node >= 12. - * - * 2. findPackageJsonUpwardFrom(require.resolve(depName, { paths: [rootDir] })) - * - * Breaks if a built-in NodeJS package name conflicts with an NPM package name - * (in Node15 `string_decoder` is introduced...) - */ -async function findPackageDir(depName: string, rootDir: string) { - let prevDir; - let dir = rootDir; - while (dir !== prevDir) { - const candidateDir = path.join(dir, 'node_modules', depName); - if (await new Promise(ok => exists(path.join(candidateDir, 'package.json'), ok))) { - return candidateDir; - } - - prevDir = dir; - dir = path.dirname(dir); // dirname('/') -> '/', dirname('c:\\') -> 'c:\\' - } - - throw new Error(`Did not find '${depName}' upwards of '${rootDir}'`); -} - -/** - * We may sometimes try to adjust a package version to a version that's incompatible with the declared requirement. - * - * For example, this recently happened for 'netmask', where the package we - * depend on has `{ requires: { netmask: '^1.0.6', } }`, but we need to force-substitute in version `2.0.1`. - * - * If NPM processes the shrinkwrap and encounters the following situation: - * - * ``` - * { - * netmask: { version: '2.0.1' }, - * resolver: { - * requires: { - * netmask: '^1.0.6' - * } - * } - * } - * ``` - * - * NPM is going to disregard the swhinkrwap and still give `resolver` its own private - * copy of netmask `^1.0.6`. - * - * We tried overriding the `requires` version, and that works for `npm install` (yay) - * but if anyone runs `npm ls` afterwards, `npm ls` is going to check the actual source - * `package.jsons` against the actual `node_modules` file tree, and complain that the - * versions don't match. - * - * We run `npm ls` in our tests to make sure our dependency tree is sane, and our customers - * might too, so this is not a great solution. - * - * To cut any discussion short in the future, we're going to detect this situation and - * tell our future selves that is cannot and will not work, and we should find another - * solution. - */ -export function checkRequiredVersions(root: PackageLock | PackageLockPackage) { - recurse(root, []); - - function recurse(entry: PackageLock | PackageLockPackage, parentChain: PackageLockEntry[]) { - // On the root, 'requires' is the value 'true', for God knows what reason. Don't care about those. - if (typeof entry.requires === 'object') { - // For every 'requires' dependency, find the version it actually got resolved to and compare. - for (const [name, range] of Object.entries(entry.requires)) { - const resolvedPackage = findResolved(name, [entry, ...parentChain]); - if (!resolvedPackage) { - continue; - } - - if (!semver.satisfies(resolvedPackage.version, range)) { - // Ruh-roh. - throw new Error(`Looks like we're trying to force '${name}' to version '${resolvedPackage.version}', but the dependency ` - + `is specified as '${range}'. This can never properly work via shrinkwrapping. Try vendoring a patched ` - + 'version of the intermediary dependencies instead.'); - } - } - } - - for (const dep of Object.values(entry.dependencies ?? {})) { - recurse(dep, [entry, ...parentChain]); - } - } - - /** - * Find a package name in a package lock tree. - */ - function findResolved(name: string, chain: PackageLockEntry[]) { - for (const level of chain) { - if (level.dependencies?.[name]) { - return level.dependencies?.[name]; - } - } - return undefined; - } -} - -/** - * Check that all packages still resolve their dependencies to the right versions - * - * We have manipulated the tree a bunch. Do a sanity check to ensure that all declared - * dependencies are satisfied. - */ -function validateTree(lock: PackageLock) { - let failed = false; - recurse(lock, [lock]); - if (failed) { - throw new Error('Could not satisfy one or more dependencies'); - } - - function recurse(pkg: PackageLockEntry, rootPath: PackageLockEntry[]) { - for (const pack of Object.values(pkg.dependencies ?? {})) { - const p = [pack, ...rootPath]; - checkRequiresOf(pack, p); - recurse(pack, p); - } - } - - // rootPath: most specific one first - function checkRequiresOf(pack: PackageLockPackage, rootPath: PackageLockEntry[]) { - for (const [name, declaredRange] of Object.entries(pack.requires ?? {})) { - const foundVersion = rootPath.map((p) => p.dependencies?.[name]?.version).find(isDefined); - if (!foundVersion) { - // eslint-disable-next-line no-console - console.error(`Dependency on ${name} not satisfied: not found`); - failed = true; - } else if (!semver.satisfies(foundVersion, declaredRange)) { - // eslint-disable-next-line no-console - console.error(`Dependency on ${name} not satisfied: declared range '${declaredRange}', found '${foundVersion}'`); - failed = true; - } - } - } -} - -function isDefined(x: A): x is NonNullable { - return x !== undefined; -} diff --git a/packages/@aws-cdk/yarn-cling/lib/types.ts b/packages/@aws-cdk/yarn-cling/lib/types.ts deleted file mode 100644 index a1e18703d..000000000 --- a/packages/@aws-cdk/yarn-cling/lib/types.ts +++ /dev/null @@ -1,58 +0,0 @@ -export interface PackageJson { - name: string; - version: string; - - /** - * Dependency name to version range - */ - dependencies?: Record; -} - -export interface YarnLock { - type: string; - /** - * Dependency range (pkg@^1.2.0) to resolved package - */ - object: Record; -} - -export interface ResolvedYarnPackage { - version: string; - resolved?: string; - integrity?: string; - - /** - * Dependency name to version range - */ - dependencies?: Record; -} - -export interface PackageLock extends PackageLockEntry { - name: string; - lockfileVersion: number; - requires: boolean; -} - -export interface PackageLockEntry { - version: string; - /** - * Package name to resolved package - */ - dependencies?: Record; -} - -export interface PackageLockPackage extends PackageLockEntry { - resolved?: string; - integrity?: string; - - /** - * Package name to version number - * - * Must be in 'dependencies' at this level or higher. - */ - requires?: Record; - - bundled?: boolean; - dev?: boolean; - optional?: boolean; -} diff --git a/packages/@aws-cdk/yarn-cling/package.json b/packages/@aws-cdk/yarn-cling/package.json deleted file mode 100644 index 948a42bd9..000000000 --- a/packages/@aws-cdk/yarn-cling/package.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "name": "@aws-cdk/yarn-cling", - "description": "Tool for generating npm-shrinkwrap from yarn.lock", - "repository": { - "type": "git", - "url": "https://github.com/aws/aws-cdk-cli", - "directory": "packages/@aws-cdk/yarn-cling" - }, - "bin": { - "yarn-cling": "bin/yarn-cling" - }, - "scripts": { - "build": "npx projen build", - "bump": "npx projen bump", - "check-for-updates": "npx projen check-for-updates", - "compile": "npx projen compile", - "default": "npx projen default", - "eslint": "npx projen eslint", - "gather-versions": "npx projen gather-versions", - "nx": "npx projen nx", - "package": "npx projen package", - "post-compile": "npx projen post-compile", - "pre-compile": "npx projen pre-compile", - "test": "npx projen test", - "test:watch": "npx projen test:watch", - "unbump": "npx projen unbump", - "watch": "npx projen watch", - "projen": "npx projen" - }, - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com", - "organization": true - }, - "devDependencies": { - "@cdklabs/eslint-plugin": "^1.3.2", - "@stylistic/eslint-plugin": "^3.1.0", - "@types/jest": "^29.5.14", - "@types/node": "^16", - "@types/semver": "^7.5.8", - "@types/yarnpkg__lockfile": "^1.1.9", - "@typescript-eslint/eslint-plugin": "^8", - "@typescript-eslint/parser": "^8", - "constructs": "^10.0.0", - "eslint": "^9", - "eslint-config-prettier": "^10.0.2", - "eslint-import-resolver-typescript": "^3.8.3", - "eslint-plugin-import": "^2.31.0", - "eslint-plugin-jest": "^28.11.0", - "eslint-plugin-jsdoc": "^50.6.3", - "eslint-plugin-prettier": "^5.2.3", - "jest": "^29.7.0", - "jest-junit": "^16", - "prettier": "^2.8", - "projen": "^0.91.13", - "ts-jest": "^29.2.6", - "typescript": "5.6" - }, - "dependencies": { - "@yarnpkg/lockfile": "^1.1.0", - "semver": "^7.7.1" - }, - "keywords": [ - "aws", - "cdk" - ], - "engines": { - "node": ">= 14.15.0" - }, - "main": "lib/index.js", - "license": "Apache-2.0", - "homepage": "https://github.com/aws/aws-cdk", - "version": "0.0.0", - "types": "lib/index.d.ts", - "private": true, - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." -} diff --git a/packages/@aws-cdk/yarn-cling/test/cling.test.ts b/packages/@aws-cdk/yarn-cling/test/cling.test.ts deleted file mode 100644 index f56e98f53..000000000 --- a/packages/@aws-cdk/yarn-cling/test/cling.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import * as path from 'path'; -import { checkRequiredVersions, generateShrinkwrap } from '../lib'; - -test('generate lock for fixture directory', async () => { - const lockFile = await generateShrinkwrap({ - packageJsonFile: path.join(__dirname, 'test-fixture', 'jsii', 'package.json'), - hoist: false, - }); - - expect(lockFile).toEqual({ - lockfileVersion: 1, - name: 'jsii', - requires: true, - version: '1.1.1', - dependencies: { - 'cdk': { - version: '2.2.2', - }, - 'aws-cdk': { - dependencies: { - 'aws-cdk-lib': { - integrity: 'sha512-pineapple', - resolved: 'https://registry.bla.com/stuff', - version: '2.3.999', - }, - }, - integrity: 'sha512-banana', - requires: { - 'aws-cdk-lib': '^2.3.4', - }, - resolved: 'https://registry.bla.com/stuff', - version: '1.2.999', - }, - }, - }); -}); - -test('generate hoisted lock for fixture directory', async () => { - const lockFile = await generateShrinkwrap({ - packageJsonFile: path.join(__dirname, 'test-fixture', 'jsii', 'package.json'), - hoist: true, - }); - - expect(lockFile).toEqual({ - lockfileVersion: 1, - name: 'jsii', - requires: true, - version: '1.1.1', - dependencies: { - 'cdk': { - version: '2.2.2', - }, - 'aws-cdk': { - integrity: 'sha512-banana', - requires: { - 'aws-cdk-lib': '^2.3.4', - }, - resolved: 'https://registry.bla.com/stuff', - version: '1.2.999', - }, - 'aws-cdk-lib': { - integrity: 'sha512-pineapple', - resolved: 'https://registry.bla.com/stuff', - version: '2.3.999', - }, - }, - }); -}); - -test('fail when requires cannot be satisfied', async () => { - const lockFile = { - lockfileVersion: 1, - name: 'jsii', - requires: true, - version: '1.1.1', - dependencies: { - jsii: { - version: '2.2.2', - requires: { - cdk: '^3.3.3', // <- this needs to be adjusted - }, - }, - cdk: { - version: '4.4.4', - }, - }, - }; - - expect(() => checkRequiredVersions(lockFile)).toThrow(/This can never/); -}); diff --git a/packages/@aws-cdk/yarn-cling/test/hoisting.test.ts b/packages/@aws-cdk/yarn-cling/test/hoisting.test.ts deleted file mode 100644 index 44f4ef357..000000000 --- a/packages/@aws-cdk/yarn-cling/test/hoisting.test.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { hoistDependencies, renderTree } from '../lib/hoisting'; -import type { PackageLockPackage } from '../lib/types'; - -type DependencyTree = PackageLockPackage; - -test('nonconflicting tree gets flattened', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: { - version: '1.0.0', - dependencies: { - leftpad: { version: '2.0.0' }, - }, - }, - numutil: { - version: '3.0.0', - dependencies: { - isodd: { version: '4.0.0' }, - }, - }, - }); - - // WHEN - hoistDependencies(tree); - - // THEN - expect(renderTree(tree)).toEqual([ - 'isodd=4.0.0', - 'leftpad=2.0.0', - 'numutil=3.0.0', - 'stringutil=1.0.0', - ]); -}); - -test('matching versions get deduped', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: { - version: '1.0.0', - dependencies: { - leftpad: { version: '2.0.0' }, - }, - }, - numutil: { - version: '3.0.0', - dependencies: { - leftpad: { version: '2.0.0' }, - isodd: { version: '4.0.0' }, - }, - }, - }); - - // WHEN - hoistDependencies(tree); - - // THEN - expect(renderTree(tree)).toEqual([ - 'isodd=4.0.0', - 'leftpad=2.0.0', - 'numutil=3.0.0', - 'stringutil=1.0.0', - ]); -}); - -test('conflicting versions get left in place', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: { - version: '1.0.0', - dependencies: { - leftpad: { version: '2.0.0' }, - }, - }, - numutil: { - version: '3.0.0', - dependencies: { - leftpad: { version: '5.0.0' }, - isodd: { version: '4.0.0' }, - }, - }, - }); - - // WHEN - hoistDependencies(tree); - - // THEN - expect(renderTree(tree)).toEqual([ - 'isodd=4.0.0', - 'leftpad=2.0.0', - 'numutil=3.0.0', - 'numutil.leftpad=5.0.0', - 'stringutil=1.0.0', - ]); -}); - -test('dependencies of deduped packages are not hoisted into useless positions', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: pkg('1.0.0', { - leftpad: pkg('2.0.0', { - spacemaker: pkg('3.0.0'), - }), - }), - leftpad: pkg('2.0.0', { - spacemaker: pkg('3.0.0'), - }), - spacemaker: pkg('4.0.0'), - }); - - // WHEN - hoistDependencies(tree); - - // THEN - expect(renderTree(tree)).toEqual([ - 'leftpad=2.0.0', - 'leftpad.spacemaker=3.0.0', - 'spacemaker=4.0.0', - 'stringutil=1.0.0', - ]); -}); - -test('dont hoist into a parent if it would cause an incorrect version there', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: pkg('1.0.0', { - spacemaker: pkg('10.0.0'), - leftPad: pkg('2.0.0', { - spacemaker: pkg('3.0.0'), - }), - }), - leftPad: pkg('1.0.0'), // Prevents previous leftPad from being hoisted - }); - - // WHEN - hoistDependencies(tree); - - // THEN - expect(renderTree(tree)).toEqual([ - 'leftPad=1.0.0', - 'spacemaker=10.0.0', - 'stringutil=1.0.0', - 'stringutil.leftPad=2.0.0', - 'stringutil.leftPad.spacemaker=3.0.0', - ]); -}); - -test('order of hoisting shouldnt produce a broken situation', () => { - // GIVEN - const tree: DependencyTree = pkg('*', { - stringutil: pkg('1.0.0', { - wrapper: pkg('100.0.0', { - leftPad: pkg('2.0.0', { - spacemaker: pkg('3.0.0'), - }), - }), - spacemaker: pkg('4.0.0'), // Prevents spacemaker from being hoisted here, but then leftPad also shouldn't be - }), - }); - - // WHEN - hoistDependencies(tree); - - // THEN - /* // Both answers are fine but the current algorithm picks the 2nd - expect(renderTree(tree)).toEqual([ - 'leftPad=2.0.0', - 'spacemaker=3.0.0', - 'stringutil=1.0.0', - 'stringutil.spacemaker=4.0.0', - 'wrapper=100.0.0', - ]); - */ - expect(renderTree(tree)).toEqual([ - 'leftPad=2.0.0', - 'leftPad.spacemaker=3.0.0', - 'spacemaker=4.0.0', - 'stringutil=1.0.0', - 'wrapper=100.0.0', - ]); -}); - -function pkg(version: string, dependencies?: Record): PackageLockPackage { - return { - version, - ...dependencies? { dependencies } : undefined, - }; -} - diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/.gitignore b/packages/@aws-cdk/yarn-cling/test/test-fixture/.gitignore deleted file mode 100644 index cf4bab9dd..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!node_modules diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/.no-packagejson-validator b/packages/@aws-cdk/yarn-cling/test/test-fixture/.no-packagejson-validator deleted file mode 100644 index 6824459f6..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/.no-packagejson-validator +++ /dev/null @@ -1 +0,0 @@ -Test fixtures should not be affected. diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/cdk/package.json b/packages/@aws-cdk/yarn-cling/test/test-fixture/cdk/package.json deleted file mode 100644 index 8594e124f..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/cdk/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "cdk", - "version": "2.2.2" -} diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json b/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json deleted file mode 100644 index 2721d93a7..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "aws-cdk-lib", - "version": "2.3.999" -} diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json b/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json deleted file mode 100644 index f074216bc..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "aws-cdk", - "version": "1.2.999", - "dependencies": { - "aws-cdk-lib": "^2.3.4" - } -} diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/cdk b/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/cdk deleted file mode 120000 index 7ce3fadc4..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/node_modules/cdk +++ /dev/null @@ -1 +0,0 @@ -../../cdk \ No newline at end of file diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/package.json b/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/package.json deleted file mode 100644 index 8508d1f52..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/jsii/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "jsii", - "version": "1.1.1", - "dependencies": { - "aws-cdk": "^1.2.3", - "cdk": "2.2.2" - } -} diff --git a/packages/@aws-cdk/yarn-cling/test/test-fixture/yarn.lock b/packages/@aws-cdk/yarn-cling/test/test-fixture/yarn.lock deleted file mode 100644 index bb94543e9..000000000 --- a/packages/@aws-cdk/yarn-cling/test/test-fixture/yarn.lock +++ /dev/null @@ -1,9 +0,0 @@ -"aws-cdk@^1.2.3": - version "1.2.999" - resolved "https://registry.bla.com/stuff" - integrity sha512-banana - -"aws-cdk-lib@^2.3.4": - version "2.3.999" - resolved "https://registry.bla.com/stuff" - integrity sha512-pineapple diff --git a/packages/@aws-cdk/yarn-cling/tsconfig.dev.json b/packages/@aws-cdk/yarn-cling/tsconfig.dev.json deleted file mode 100644 index 18ee3a655..000000000 --- a/packages/@aws-cdk/yarn-cling/tsconfig.dev.json +++ /dev/null @@ -1,38 +0,0 @@ -// ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -{ - "compilerOptions": { - "alwaysStrict": true, - "declaration": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "inlineSources": true, - "lib": [ - "es2019" - ], - "module": "CommonJS", - "noEmitOnError": false, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "strict": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "stripInternal": true, - "target": "ES2019", - "composite": true, - "outDir": "lib" - }, - "include": [ - "lib/**/*.ts", - "test/**/*.ts" - ], - "exclude": [ - "node_modules" - ], - "references": [] -} diff --git a/packages/@aws-cdk/yarn-cling/tsconfig.json b/packages/@aws-cdk/yarn-cling/tsconfig.json deleted file mode 100644 index a9cd6a329..000000000 --- a/packages/@aws-cdk/yarn-cling/tsconfig.json +++ /dev/null @@ -1,36 +0,0 @@ -// ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -{ - "compilerOptions": { - "rootDir": "lib", - "outDir": "lib", - "alwaysStrict": true, - "declaration": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "inlineSources": true, - "lib": [ - "es2019" - ], - "module": "CommonJS", - "noEmitOnError": false, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "strict": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "stripInternal": true, - "target": "ES2019", - "composite": true - }, - "include": [ - "lib/**/*.ts" - ], - "exclude": [], - "references": [] -} diff --git a/packages/aws-cdk/.projen/deps.json b/packages/aws-cdk/.projen/deps.json index 69a15ffb7..17f0feea5 100644 --- a/packages/aws-cdk/.projen/deps.json +++ b/packages/aws-cdk/.projen/deps.json @@ -1,9 +1,5 @@ { "dependencies": [ - { - "name": "@aws-cdk/cdk-build-tools", - "type": "build" - }, { "name": "@aws-cdk/cli-plugin-contract", "type": "build" @@ -20,10 +16,6 @@ "name": "@aws-cdk/user-input-gen", "type": "build" }, - { - "name": "@aws-cdk/yarn-cling", - "type": "build" - }, { "name": "@cdklabs/eslint-plugin", "type": "build" diff --git a/packages/aws-cdk/.projen/tasks.json b/packages/aws-cdk/.projen/tasks.json index be3d95c28..a779c1065 100644 --- a/packages/aws-cdk/.projen/tasks.json +++ b/packages/aws-cdk/.projen/tasks.json @@ -101,7 +101,7 @@ "name": "gather-versions", "steps": [ { - "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" aws-cdk MAJOR --deps @aws-cdk/cloud-assembly-schema @aws-cdk/cloudformation-diff @aws-cdk/yarn-cling @aws-cdk/user-input-gen @aws-cdk/node-bundle @aws-cdk/cdk-build-tools @aws-cdk/cli-plugin-contract cdk-assets @aws-cdk/tmp-toolkit-helpers", + "exec": "node -e \"require(path.join(path.dirname(require.resolve('cdklabs-projen-project-types')), 'yarn', 'gather-versions.exec.js'))\" aws-cdk MAJOR --deps @aws-cdk/cloud-assembly-schema @aws-cdk/cloudformation-diff @aws-cdk/user-input-gen @aws-cdk/node-bundle @aws-cdk/cli-plugin-contract cdk-assets @aws-cdk/tmp-toolkit-helpers", "receiveArgs": true } ] diff --git a/packages/aws-cdk/package.json b/packages/aws-cdk/package.json index c2e4ae313..156e8470a 100644 --- a/packages/aws-cdk/package.json +++ b/packages/aws-cdk/package.json @@ -34,12 +34,10 @@ "organization": true }, "devDependencies": { - "@aws-cdk/cdk-build-tools": "^0.0.0", "@aws-cdk/cli-plugin-contract": "^0.0.0", "@aws-cdk/node-bundle": "^0.0.0", "@aws-cdk/tmp-toolkit-helpers": "^0.0.0", "@aws-cdk/user-input-gen": "^0.0.0", - "@aws-cdk/yarn-cling": "^0.0.0", "@cdklabs/eslint-plugin": "^1.3.2", "@octokit/rest": "^21.1.1", "@stylistic/eslint-plugin": "^3.1.0", diff --git a/packages/aws-cdk/test/_helpers/bockfs.ts b/packages/aws-cdk/test/_helpers/bockfs.ts new file mode 100644 index 000000000..74257e4d8 --- /dev/null +++ b/packages/aws-cdk/test/_helpers/bockfs.ts @@ -0,0 +1,81 @@ +/* eslint-disable import/order */ +// A not-so-fake filesystem mock similar to mock-fs +// +// mock-fs is super convenient but we can't always use it: +// - When you use console.log() jest wants to load things from the filesystem (which fails). +// - When you make AWS calls the SDK wants to load things from the filesystem (which fails). +// +// Therefore, something similar which uses tempdirs on your actual disk. +// +// The big downside compared to mockfs is that you need to use bockfs.path() to translate +// fake paths to real paths. +import * as os from 'os'; +import * as path_ from 'path'; +import * as fs from 'fs-extra'; + +const bockFsRoot = fs.realpathSync(fs.mkdtempSync(path_.join(os.tmpdir(), 'bockfs'))); +let oldCwd: string | undefined; + +function bockfs(files: Record) { + oldCwd = process.cwd(); + for (const [fileName, contents] of Object.entries(files)) { + bockfs.write(fileName, contents); + } +} + +namespace bockfs { + /** + * Write contents to a fake file + */ + export function write(fakeFilename: string, contents: string) { + const fullPath = path(fakeFilename); + fs.mkdirSync(path_.dirname(fullPath), { recursive: true }); + fs.writeFileSync(fullPath, contents, { encoding: 'utf-8' }); + } + + /** + * Turn a fake path into a real path + */ + export function path(fakePath: string) { + if (fakePath.startsWith('/')) { + fakePath = fakePath.slice(1); + } // Force path to be non-absolute + return path_.join(bockFsRoot, fakePath); + } + + /** + * Change to a fake directory + * + * @returns A template literal function to turn a fake path into a real path. Relative paths are assumed to be in the working dir. + */ + export function workingDirectory(fakePath: string): (parts: TemplateStringsArray) => string { + process.chdir(path(fakePath)); + + return function (elements: TemplateStringsArray) { + const fullPath = elements.join(''); + if (!fullPath.startsWith('/')) { + return path(path_.join(fakePath, fullPath)); + } + + return path(fullPath); + }; + } + + export function executable(...fakePaths: string[]) { + for (const fakepath of fakePaths) { + fs.chmodSync(path(fakepath), '755'); + } + } + + /** + * Remove all files and restore working directory + */ + export function restore() { + if (oldCwd) { + process.chdir(oldCwd); + } + fs.removeSync(bockFsRoot); + } +} + +export default bockfs; diff --git a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts b/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts index ab3e0bc2c..ea0f4b5e2 100644 --- a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { bockfs } from '@aws-cdk/cdk-build-tools'; +import bockfs from '../../_helpers/bockfs'; import * as fs from 'fs-extra'; import { AccountAccessKeyCache } from '../../../lib/api/aws-auth/account-cache'; import { withMocked } from '../../util'; diff --git a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts b/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts index 0fcc09a14..bd0446894 100644 --- a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts @@ -13,7 +13,7 @@ * calls and locally fake an STS Endpoint using the `FakeSts` class. */ import * as os from 'os'; -import { bockfs } from '@aws-cdk/cdk-build-tools'; +import bockfs from '../../_helpers/bockfs'; import * as cxapi from '@aws-cdk/cx-api'; import * as fromEnv from '@aws-sdk/credential-provider-env'; import * as promptly from 'promptly'; @@ -741,7 +741,7 @@ function sdkConfig(sdk: SDK): ConfigurationOptions { */ function prepareCreds(options: PrepareCredsOptions) { function convertSections(sections?: Record) { - const ret = []; + const ret: string[] = []; for (const [profile, user] of Object.entries(sections ?? {})) { ret.push(`[${profile}]`); diff --git a/packages/aws-cdk/test/api/cxapp/exec.test.ts b/packages/aws-cdk/test/api/cxapp/exec.test.ts index 5eb6471e8..031426871 100644 --- a/packages/aws-cdk/test/api/cxapp/exec.test.ts +++ b/packages/aws-cdk/test/api/cxapp/exec.test.ts @@ -1,6 +1,6 @@ /* eslint-disable import/order */ jest.mock('child_process'); -import { bockfs } from '@aws-cdk/cdk-build-tools'; +import bockfs from '../../_helpers/bockfs'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import * as cdk from 'aws-cdk-lib'; import * as semver from 'semver'; diff --git a/packages/aws-cdk/tsconfig.dev.json b/packages/aws-cdk/tsconfig.dev.json index 870390aca..b776637ea 100644 --- a/packages/aws-cdk/tsconfig.dev.json +++ b/packages/aws-cdk/tsconfig.dev.json @@ -48,15 +48,9 @@ { "path": "../cdk-assets" }, - { - "path": "../@aws-cdk/yarn-cling" - }, { "path": "../@aws-cdk/node-bundle" }, - { - "path": "../@aws-cdk/cdk-build-tools" - }, { "path": "../@aws-cdk/user-input-gen" }, diff --git a/packages/aws-cdk/tsconfig.json b/packages/aws-cdk/tsconfig.json index 5a43d097d..0143b2913 100644 --- a/packages/aws-cdk/tsconfig.json +++ b/packages/aws-cdk/tsconfig.json @@ -47,15 +47,9 @@ { "path": "../cdk-assets" }, - { - "path": "../@aws-cdk/yarn-cling" - }, { "path": "../@aws-cdk/node-bundle" }, - { - "path": "../@aws-cdk/cdk-build-tools" - }, { "path": "../@aws-cdk/user-input-gen" }, diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 393d79ec2..74dc35834 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -39,18 +39,12 @@ { "path": "packages/@aws-cdk/cloudformation-diff" }, - { - "path": "packages/@aws-cdk/yarn-cling" - }, { "path": "packages/@aws-cdk/user-input-gen" }, { "path": "packages/@aws-cdk/node-bundle" }, - { - "path": "packages/@aws-cdk/cdk-build-tools" - }, { "path": "packages/@aws-cdk/cli-plugin-contract" }, diff --git a/tsconfig.json b/tsconfig.json index 9840db28c..d04636fc1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -36,18 +36,12 @@ { "path": "packages/@aws-cdk/cloudformation-diff" }, - { - "path": "packages/@aws-cdk/yarn-cling" - }, { "path": "packages/@aws-cdk/user-input-gen" }, { "path": "packages/@aws-cdk/node-bundle" }, - { - "path": "packages/@aws-cdk/cdk-build-tools" - }, { "path": "packages/@aws-cdk/cli-plugin-contract" },