diff --git a/babel.config.js b/babel.config.js index 6eb98d7d806..c369ce40b4f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,7 @@ // This file is require for running tests only!! -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); module.exports = { babelrc: true, - babelrcRoots: allPackages() + babelrcRoots: allWorkspaces() }; diff --git a/jest.config.js b/jest.config.js index 2b85281d7fa..4448f96d53e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,8 +1,8 @@ const fs = require("fs"); const path = require("path"); -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); -const projects = allPackages() +const projects = allWorkspaces() .map(pkg => { if (!fs.existsSync(path.join(pkg, "jest.config.js"))) { return null; diff --git a/package.json b/package.json index a817cdb61a2..bbbb15cbdc7 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "webiny-versions": "node ./scripts/webinyVersions.js", "release-latest": "node ./scripts/releaseLatest.js", "lint-staged": "lint-staged", - "postinstall": "node ./scripts/linkPackages.js", + "postinstall": "node ./scripts/linkWorkspaces.js", "prepublishOnly": "node scripts/prepublishOnly.js", "prettier": "prettier \"**/**/*.{js,jsx,ts,tsx}\" --config .prettierrc.js", "prettier:check": "yarn prettier --check", diff --git a/packages/cli-plugin-workspaces/commands/list.js b/packages/cli-plugin-workspaces/commands/list.js index 1da2971942e..a2c857a0d68 100644 --- a/packages/cli-plugin-workspaces/commands/list.js +++ b/packages/cli-plugin-workspaces/commands/list.js @@ -1,13 +1,13 @@ const { join } = require("path"); const chalk = require("chalk"); -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); const outputJSON = obj => { console.log(JSON.stringify(obj, null, 2)); }; module.exports = async ({ json, withPath }) => { - const packages = allPackages().reduce((acc, folder) => { + const workspaces = allWorkspaces().reduce((acc, folder) => { const json = require(join(folder, "package.json")); acc[json.name] = folder; return acc; @@ -16,16 +16,16 @@ module.exports = async ({ json, withPath }) => { if (json) { // `withPath` outputs a key => value object, containing workspace name and absolute path if (withPath) { - outputJSON(packages); + outputJSON(workspaces); } else { - outputJSON(Object.keys(packages)); + outputJSON(Object.keys(workspaces)); } return; } - Object.keys(packages).forEach(name => { + Object.keys(workspaces).forEach(name => { if (withPath) { - console.log(`${chalk.green(name)} (${chalk.blue(packages[name])})`); + console.log(`${chalk.green(name)} (${chalk.blue(workspaces[name])})`); } else { console.log(chalk.green(name)); } diff --git a/packages/cli-plugin-workspaces/commands/utils.js b/packages/cli-plugin-workspaces/commands/utils.js index cb9390cbc66..92523b71ad8 100644 --- a/packages/cli-plugin-workspaces/commands/utils.js +++ b/packages/cli-plugin-workspaces/commands/utils.js @@ -1,7 +1,7 @@ const { Graph, alg } = require("graphlib"); const { join, resolve } = require("path"); const multimatch = require("multimatch"); -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); const createGraph = packages => { const graph = new Graph(); @@ -46,7 +46,7 @@ const validateGraph = graph => { }; const getPackages = ({ script, folders, scopes }) => { - return allPackages() + return allWorkspaces() .filter(pkgPath => { if (!folders.length) { return true; diff --git a/packages/cwp-template-aws/template/babel.config.js b/packages/cwp-template-aws/template/babel.config.js index e98feb324c5..c5278f0eeb3 100644 --- a/packages/cwp-template-aws/template/babel.config.js +++ b/packages/cwp-template-aws/template/babel.config.js @@ -1,7 +1,7 @@ // This file is required for running tests only!! -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); module.exports = { babelrc: true, - babelrcRoots: allPackages() + babelrcRoots: allWorkspaces() }; diff --git a/packages/cwp-template-aws/template/dependencies.json b/packages/cwp-template-aws/template/dependencies.json index c7530e9a2b7..75000fe439a 100644 --- a/packages/cwp-template-aws/template/dependencies.json +++ b/packages/cwp-template-aws/template/dependencies.json @@ -57,8 +57,8 @@ "scripts": { "setup-repo": "node ./scripts/setupRepository.js", "setup-env-files": "node ./scripts/setupEnvFiles.js", - "link-packages": "node ./scripts/linkPackages.js", - "postinstall": "yarn link-packages", + "link-workspaces": "node ./scripts/linkWorkspaces.js", + "postinstall": "yarn link-workspaces", "test": "jest --config jest.config.js" } } diff --git a/packages/cwp-template-aws/template/jest.config.js b/packages/cwp-template-aws/template/jest.config.js index 2b85281d7fa..4448f96d53e 100644 --- a/packages/cwp-template-aws/template/jest.config.js +++ b/packages/cwp-template-aws/template/jest.config.js @@ -1,8 +1,8 @@ const fs = require("fs"); const path = require("path"); -const { allPackages } = require("@webiny/project-utils/packages"); +const { allWorkspaces } = require("@webiny/project-utils/workspaces"); -const projects = allPackages() +const projects = allWorkspaces() .map(pkg => { if (!fs.existsSync(path.join(pkg, "jest.config.js"))) { return null; diff --git a/packages/cwp-template-aws/template/scripts/linkPackages.js b/packages/cwp-template-aws/template/scripts/linkPackages.js deleted file mode 100644 index f89f29342c4..00000000000 --- a/packages/cwp-template-aws/template/scripts/linkPackages.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This tool will re-link monorepo packages to one of the following directories (by priority): - * - {package}/package.json -> publishConfig.directory - * - lerna.json -> command.publish.contents - * - package root directory - */ -(async () => { - const { linkPackages } = require("@webiny/project-utils/packages"); - await linkPackages(); -})(); diff --git a/packages/cwp-template-aws/template/scripts/linkWorkspaces.js b/packages/cwp-template-aws/template/scripts/linkWorkspaces.js new file mode 100644 index 00000000000..5828eaefeee --- /dev/null +++ b/packages/cwp-template-aws/template/scripts/linkWorkspaces.js @@ -0,0 +1,10 @@ +/** + * This tool will re-link monorepo workspaces to one of the following directories (by priority): + * - {workspace}/package.json -> publishConfig.directory + * - lerna.json -> command.publish.contents + * - workspace root directory + */ +(async () => { + const { linkWorkspaces } = require("@webiny/project-utils/workspaces"); + await linkWorkspaces(); +})(); diff --git a/packages/project-utils/aliases/jest.js b/packages/project-utils/aliases/jest.js deleted file mode 100644 index 8c3daa48f71..00000000000 --- a/packages/project-utils/aliases/jest.js +++ /dev/null @@ -1,17 +0,0 @@ -const path = require("path"); -const fs = require("fs"); -const readJson = require("read-json-sync"); -const packages = require("../packages"); - -module.exports = packages.reduce((aliases, dir) => { - try { - const json = readJson(path.join(dir, "package.json")); - if (fs.existsSync(path.join(dir, "dist"))) { - aliases[`^${json.name}$`] = `${json.name}/dist`; - aliases[`^${json.name}/(.*)$`] = `${json.name}/dist/\\1`; - } - } catch (err) { - // No package.json, continue. - } - return aliases; -}, {}); diff --git a/packages/project-utils/aliases/webpack.js b/packages/project-utils/aliases/webpack.js deleted file mode 100644 index 64454a08563..00000000000 --- a/packages/project-utils/aliases/webpack.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require("path"); -const fs = require("fs"); -const readJson = require("read-json-sync"); -const packages = require("../packages"); - -module.exports = packages.reduce((aliases, dir) => { - try { - const json = readJson(path.join(dir, "package.json")); - if (fs.existsSync(path.join(dir, "dist"))) { - aliases[`${json.name}`] = `${json.name}/dist`; - } - } catch (err) { - // No package.json, continue. - } - return aliases; -}, {}); diff --git a/packages/project-utils/bundling/app/config/paths.js b/packages/project-utils/bundling/app/config/paths.js index 9189fac2d01..651cb80d8ee 100644 --- a/packages/project-utils/bundling/app/config/paths.js +++ b/packages/project-utils/bundling/app/config/paths.js @@ -3,7 +3,7 @@ const path = require("path"); const fs = require("fs"); const url = require("url"); -const { allPackages } = require("../../../packages"); +const { allWorkspaces } = require("../../../workspaces"); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 @@ -81,6 +81,6 @@ module.exports = ({ appIndexJs }) => ({ appNodeModules: resolveApp("node_modules"), publicUrl: getPublicUrl(resolveApp("package.json")), servedPath: getServedPath(resolveApp("package.json")), - allPackages: allPackages(), + allWorkspaces: allWorkspaces(), moduleFileExtensions }); diff --git a/packages/project-utils/bundling/app/config/webpack.config.js b/packages/project-utils/bundling/app/config/webpack.config.js index 82ca370e46d..05d0b643ec9 100644 --- a/packages/project-utils/bundling/app/config/webpack.config.js +++ b/packages/project-utils/bundling/app/config/webpack.config.js @@ -360,7 +360,7 @@ module.exports = function(webpackEnv, { paths, babelCustomizer }) { return false; } - return paths.allPackages.some(p => file.includes(p)); + return paths.allWorkspaces.some(p => file.includes(p)); }, exclude: /node_modules/ }, @@ -384,7 +384,7 @@ module.exports = function(webpackEnv, { paths, babelCustomizer }) { // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, - include: [paths.appSrc, paths.appIndexJs, ...paths.allPackages], + include: [paths.appSrc, paths.appIndexJs, ...paths.allWorkspaces], loader: require.resolve("babel-loader"), options: babelCustomizer({ sourceType: "unambiguous", diff --git a/packages/project-utils/packages/index.js b/packages/project-utils/packages/index.js deleted file mode 100644 index 40d03a9c7b5..00000000000 --- a/packages/project-utils/packages/index.js +++ /dev/null @@ -1,8 +0,0 @@ -const { linkPackages } = require("./linkPackages"); - -const allPackages = () => { - const path = require("path"); - return require("get-yarn-workspaces")().map(pkg => pkg.replace(/\//g, path.sep)); -}; - -module.exports = { allPackages, linkPackages }; diff --git a/packages/project-utils/workspaces/index.js b/packages/project-utils/workspaces/index.js new file mode 100644 index 00000000000..f472f1f3a91 --- /dev/null +++ b/packages/project-utils/workspaces/index.js @@ -0,0 +1,8 @@ +const { linkWorkspaces } = require("./linkWorkspaces"); + +const allWorkspaces = () => { + const path = require("path"); + return require("get-yarn-workspaces")().map(pkg => pkg.replace(/\//g, path.sep)); +}; + +module.exports = { allWorkspaces, linkWorkspaces }; diff --git a/packages/project-utils/packages/linkPackages.js b/packages/project-utils/workspaces/linkPackages.js similarity index 100% rename from packages/project-utils/packages/linkPackages.js rename to packages/project-utils/workspaces/linkPackages.js diff --git a/scripts/cz-adapter/package.json b/scripts/cz-adapter/package.json index e69acb4016e..7e052fd801d 100644 --- a/scripts/cz-adapter/package.json +++ b/scripts/cz-adapter/package.json @@ -1,4 +1,4 @@ { "name": "webiny-cz-adapter", "version": "1.0.0" -} \ No newline at end of file +} diff --git a/scripts/layers/layers.json b/scripts/layers/layers.json index aff76b03410..38fd4911852 100644 --- a/scripts/layers/layers.json +++ b/scripts/layers/layers.json @@ -1,20 +1,20 @@ { - "webiny-v4-sharp": { - "us-east-1": "arn:aws:lambda:us-east-1:632417926021:layer:webiny-v4-sharp:1", - "us-east-2": "arn:aws:lambda:us-east-2:632417926021:layer:webiny-v4-sharp:1", - "us-west-1": "arn:aws:lambda:us-west-1:632417926021:layer:webiny-v4-sharp:1", - "us-west-2": "arn:aws:lambda:us-west-2:632417926021:layer:webiny-v4-sharp:1", - "ap-south-1": "arn:aws:lambda:ap-south-1:632417926021:layer:webiny-v4-sharp:1", - "ap-northeast-2": "arn:aws:lambda:ap-northeast-2:632417926021:layer:webiny-v4-sharp:1", - "ap-northeast-1": "arn:aws:lambda:ap-northeast-1:632417926021:layer:webiny-v4-sharp:1", - "ca-central-1": "arn:aws:lambda:ca-central-1:632417926021:layer:webiny-v4-sharp:1", - "eu-central-1": "arn:aws:lambda:eu-central-1:632417926021:layer:webiny-v4-sharp:1", - "eu-west-1": "arn:aws:lambda:eu-west-1:632417926021:layer:webiny-v4-sharp:1", - "eu-west-2": "arn:aws:lambda:eu-west-2:632417926021:layer:webiny-v4-sharp:1", - "eu-west-3": "arn:aws:lambda:eu-west-3:632417926021:layer:webiny-v4-sharp:1", - "eu-north-1": "arn:aws:lambda:eu-north-1:632417926021:layer:webiny-v4-sharp:1", - "ap-southeast-1": "arn:aws:lambda:ap-southeast-1:632417926021:layer:webiny-v4-sharp:1", - "ap-southeast-2": "arn:aws:lambda:ap-southeast-2:632417926021:layer:webiny-v4-sharp:1", - "sa-east-1": "arn:aws:lambda:sa-east-1:632417926021:layer:webiny-v4-sharp:1" - } + "webiny-v4-sharp": { + "us-east-1": "arn:aws:lambda:us-east-1:632417926021:layer:webiny-v4-sharp:1", + "us-east-2": "arn:aws:lambda:us-east-2:632417926021:layer:webiny-v4-sharp:1", + "us-west-1": "arn:aws:lambda:us-west-1:632417926021:layer:webiny-v4-sharp:1", + "us-west-2": "arn:aws:lambda:us-west-2:632417926021:layer:webiny-v4-sharp:1", + "ap-south-1": "arn:aws:lambda:ap-south-1:632417926021:layer:webiny-v4-sharp:1", + "ap-northeast-2": "arn:aws:lambda:ap-northeast-2:632417926021:layer:webiny-v4-sharp:1", + "ap-northeast-1": "arn:aws:lambda:ap-northeast-1:632417926021:layer:webiny-v4-sharp:1", + "ca-central-1": "arn:aws:lambda:ca-central-1:632417926021:layer:webiny-v4-sharp:1", + "eu-central-1": "arn:aws:lambda:eu-central-1:632417926021:layer:webiny-v4-sharp:1", + "eu-west-1": "arn:aws:lambda:eu-west-1:632417926021:layer:webiny-v4-sharp:1", + "eu-west-2": "arn:aws:lambda:eu-west-2:632417926021:layer:webiny-v4-sharp:1", + "eu-west-3": "arn:aws:lambda:eu-west-3:632417926021:layer:webiny-v4-sharp:1", + "eu-north-1": "arn:aws:lambda:eu-north-1:632417926021:layer:webiny-v4-sharp:1", + "ap-southeast-1": "arn:aws:lambda:ap-southeast-1:632417926021:layer:webiny-v4-sharp:1", + "ap-southeast-2": "arn:aws:lambda:ap-southeast-2:632417926021:layer:webiny-v4-sharp:1", + "sa-east-1": "arn:aws:lambda:sa-east-1:632417926021:layer:webiny-v4-sharp:1" + } } diff --git a/scripts/linkPackages.js b/scripts/linkPackages.js deleted file mode 100644 index b44f09813b6..00000000000 --- a/scripts/linkPackages.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This tool will re-link monorepo packages to one of the following directories (by priority): - * - {package}/package.json -> publishConfig.directory - * - lerna.json -> command.publish.contents - * - package root directory - */ -(async () => { - const { linkPackages } = require("../packages/project-utils/packages"); - await linkPackages(); -})(); diff --git a/scripts/linkWorkspaces.js b/scripts/linkWorkspaces.js new file mode 100644 index 00000000000..60462d02128 --- /dev/null +++ b/scripts/linkWorkspaces.js @@ -0,0 +1,10 @@ +/** + * This tool will re-link monorepo workspaces to one of the following directories (by priority): + * - {workspaces}/package.json -> publishConfig.directory + * - lerna.json -> command.publish.contents + * - workspace root directory + */ +(async () => { + const { linkWorkspaces } = require("../packages/project-utils/workspaces"); + await linkWorkspaces(); +})();