From 18aa8b2bebc2d36230e9003123293f65a8301031 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 21 Jul 2020 22:21:39 +0100 Subject: [PATCH 1/2] add recast as a dependency --- packages/ember-cli-fastboot/package.json | 1 + yarn.lock | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index f479f3a49..f350d5fad 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -39,6 +39,7 @@ "fs-extra": "^7.0.0", "json-stable-stringify": "^1.0.1", "md5-hex": "^2.0.0", + "recast": "^0.19.1", "silent-error": "^1.1.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 3f530a5c4..cbc795b41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11772,7 +11772,7 @@ parse5@5.1.0: resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.0.tgz#c59341c9723f414c452975564c7c00a68d58acd2" integrity sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ== -parse5@5.1.1: +parse5@5.1.1, parse5@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178" integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug== @@ -11784,11 +11784,6 @@ parse5@^3.0.3: dependencies: "@types/node" "*" -parse5@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178" - integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug== - parseqs@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" @@ -12467,6 +12462,16 @@ recast@^0.18.1: private "^0.1.8" source-map "~0.6.1" +recast@^0.19.1: + version "0.19.1" + resolved "https://registry.yarnpkg.com/recast/-/recast-0.19.1.tgz#555f3612a5a10c9f44b9a923875c51ff775de6c8" + integrity sha512-8FCjrBxjeEU2O6I+2hyHyBFH1siJbMBLwIRvVr1T3FD2cL754sOaJDsJ/8h3xYltasbJ8jqWRIhMuDGBSiSbjw== + dependencies: + ast-types "0.13.3" + esprima "~4.0.0" + private "^0.1.8" + source-map "~0.6.1" + rechoir@^0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" From 6f929b5a6368ef1e50f6ad6a5fa494382fc1ba10 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 21 Jul 2020 22:22:23 +0100 Subject: [PATCH 2/2] add default blueprint that adds `node: current` to targets --- .../blueprints/ember-cli-fastboot/index.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js diff --git a/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js b/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js new file mode 100644 index 000000000..db6f60f89 --- /dev/null +++ b/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js @@ -0,0 +1,44 @@ +/* eslint-env node */ +const recast = require('recast'); +const { readFileSync, writeFileSync } = require('fs'); + +module.exports = { + description: '', + normalizeEntityName() { + // no-op + }, + + afterInstall() { + let targetsFile = './config/targets.js' + + if(this.project.isEmberCLIAddon()) { + targetsFile = './tests/dummy/config/targets.js'; + } + + const targetsAst = recast.parse(readFileSync(targetsFile)); + + recast.visit(targetsAst, { + visitAssignmentExpression (path) { + let node = path.node; + + if (node.left.object.name === 'module' && node.left.property.name === 'exports') { + let nodeProperty = node.right.properties.find(property => property.key.name === 'node'); + + if(!nodeProperty) { + let builders = recast.types.builders; + nodeProperty = builders.property( + 'init', + builders.identifier('node'), + builders.literal('current') + ); + node.right.properties.push(nodeProperty); + } + } + + this.traverse(path); + } + }); + + writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code); + } +};