Skip to content

Commit

Permalink
Adjust require() validation to only JS
Browse files Browse the repository at this point in the history
  • Loading branch information
tkcranny committed Oct 24, 2024
1 parent f73fa8e commit f87c4b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/oclif/commands/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ScaffoldCommand extends BaseCommand {

if (isValidAppInstall().valid) {
const success = isValidEntryFileUpdate(
context.language,
context.indexFileResolved,
context.actionType,
context.templateContext.KEY
Expand Down
15 changes: 3 additions & 12 deletions packages/cli/src/smoke-tests/smoke-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,9 @@ describe('smoke tests - setup will take some time', function () {
const newAppDir = path.join(context.workdir, 'scaffold-town-ts');
fs.existsSync(newAppDir).should.be.true();

runCommand(
context.cliBin,
[
'scaffold',
'trigger',
'neat',
'--entry=src/index.ts', // TODO: Support automatic entry file detection for TS
'--dest=src/triggers', // TODO: Support automatic dest file detection for TS
'--test-dest=src/test/triggers', // TODO: Support automatic test dest file detection for TS
],
{ cwd: newAppDir }
);
runCommand(context.cliBin, ['scaffold', 'trigger', 'neat'], {
cwd: newAppDir,
});

const appIndexTs = path.join(newAppDir, 'src', 'index.ts');
fs.existsSync(appIndexTs).should.be.true();
Expand Down
21 changes: 14 additions & 7 deletions packages/cli/src/utils/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,20 @@ const writeTemplateFile = async ({
const getRelativeRequirePath = (entryFilePath, newFilePath) =>
path.relative(path.dirname(entryFilePath), newFilePath);

const isValidEntryFileUpdate = (entryFilePath, actionType, newActionKey) => {
// ensure a clean access
delete require.cache[require.resolve(entryFilePath)];

// this line fails if `npm install` hasn't been run, since core isn't present yet.
const rewrittenIndex = require(entryFilePath);
return Boolean(_.get(rewrittenIndex, [plural(actionType), newActionKey]));
const isValidEntryFileUpdate = (
language,
indexFileResolved,
actionType,
newActionKey
) => {
if (language === 'js') {
// ensure a clean access
delete require.cache[require.resolve(indexFileResolved)];
// this line fails if `npm install` hasn't been run, since core isn't present yet.
const rewrittenIndex = require(indexFileResolved);
return Boolean(_.get(rewrittenIndex, [plural(actionType), newActionKey]));
}
return true;
};

/**
Expand Down

0 comments on commit f87c4b8

Please sign in to comment.