Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/lib/run-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const cloneDeep = require('lodash.clonedeep')
const express = require('express')
const fs = require('fs-extra')
const path = require('node:path')
const fsp = require('node:fs/promises')
const https = require('node:https')
const crypto = require('node:crypto')
const livereload = require('livereload')
Expand Down Expand Up @@ -316,9 +317,25 @@ async function invokeSequence ({ actionRequestContext, logger }) {
* @returns {object} the action function
*/
async function defaultActionLoader ({ distFolder, packageName, actionName }) {
const actionFolder = path.join(distFolder, packageName, actionName)
const actionPath = `${actionFolder}-temp/index.js`
delete require.cache[actionPath]
const actionTempDir = path.join(distFolder, packageName, `${actionName}-temp`)
const actionPath = path.join(actionTempDir, 'index.js')

// Bundled actions are CommonJS. If an ancestor app package.json has "type": "module",
// Node would treat index.js here as ESM unless this directory declares otherwise.
try {
await fsp.access(actionPath)
} catch {
return require(actionPath)?.main
}

await fsp.writeFile(path.join(actionTempDir, 'package.json'), '{"type":"commonjs"}', 'utf8')

try {
delete require.cache[require.resolve(actionPath)]
} catch {
// ignore: module not yet loaded
}

return require(actionPath)?.main
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"commonjs"}
Loading