From b8e150019073145f7cfc6c4ad043cb373e150f6d Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 11 Oct 2023 11:56:55 -0400 Subject: [PATCH] fix(devkit): pass filepath to ejs for include statements (#19517) --- package.json | 1 + packages/devkit/src/generators/generate-files.ts | 6 ++++-- pnpm-lock.yaml | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 09372b3cd6dde..0477108793fa8 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "@testing-library/react": "13.4.0", "@types/cytoscape": "^3.18.2", "@types/detect-port": "^1.3.2", + "@types/ejs": "3.1.2", "@types/eslint": "~8.44.2", "@types/express": "4.17.14", "@types/flat": "^5.0.1", diff --git a/packages/devkit/src/generators/generate-files.ts b/packages/devkit/src/generators/generate-files.ts index f2e51c36a4fae..ff2d2c448fa00 100644 --- a/packages/devkit/src/generators/generate-files.ts +++ b/packages/devkit/src/generators/generate-files.ts @@ -34,7 +34,7 @@ export function generateFiles( target: string, substitutions: { [k: string]: any } ): void { - const ejs = require('ejs'); + const ejs: typeof import('ejs') = require('ejs'); const files = allFilesInDir(srcFolder); if (files.length === 0) { @@ -56,7 +56,9 @@ export function generateFiles( } else { const template = readFileSync(filePath, 'utf-8'); try { - newContent = ejs.render(template, substitutions, {}); + newContent = ejs.render(template, substitutions, { + filename: filePath, + }); } catch (e) { logger.error(`Error in ${filePath.replace(`${tree.root}/`, '')}:`); throw e; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 394529e430e78..fc8d7085ca443 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -404,6 +404,9 @@ devDependencies: '@types/detect-port': specifier: ^1.3.2 version: 1.3.2 + '@types/ejs': + specifier: 3.1.2 + version: 3.1.2 '@types/eslint': specifier: ~8.44.2 version: 8.44.2