Support `tsconfig.json` `paths` imports / monorepository workspaces
KeithGillette opened this issue · comments
Current Behavior
Related to this previously reported limitation of Zapier CLI stemming from its design of copying project source code to a temporary directory, zapier build
produces Error: Cannot find module
when attempting to import from a module defined using the tsconfig.json
paths
property, as illustrated in the following error generated in our Nx workspace:
Error from zapier build
:
✔ Copying project to temp directory
✔ Installing project dependencies
✔ Applying entry point file
✖ Building app definition.json
› Error: Cannot find module '@tasktrain/shared/core/application/oauth'
› Require stack:
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/lib/applications/zapier/src/triggers/assignee-list.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/lib/applications/zapier/src/index.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/index.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/node_modules/zapier-platform-core/src/index.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/node_modules/zapier-platform-core/index.js
› - /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/zapier-fee12db4/zapierwrapper.js
› - /path/to/node_modules/zapier-platform-cli/src/utils/build.js
› - /path/to/node_modules/zapier-platform-cli/src/oclif/commands/build.js
› - /path/to/node_modules/zapier-platform-cli/src/oclif/commands/push.js
› - /path/to/node_modules/@oclif/config/lib/plugin.js
› - /path/to/node_modules/@oclif/config/lib/config.js
› - /path/to/node_modules/@oclif/config/lib/index.js
› - /path/to/node_modules/@oclif/command/lib/command.js
› - /path/to/node_modules/@oclif/command/lib/index.js
› - /path/to/node_modules/zapier-platform-cli/src/bin/run
applications/zapier/tsconfig.json
:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "../../",
"module": "commonjs",
"outDir": "./lib",
"target": "es2019"
}
}
workspace tsconfig.json
:
{
"compileOnSave": false,
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"importHelpers": true,
"lib": [
"ES2018",
"dom"
],
"module": "es2020",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "./dist/out-tsc",
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es2015",
"paths": {
"@tasktrain/shared/core/application/oauth": [
"libraries/shared/core/application/oauth/src/index.ts"
]
}
}
}
Desired Behavior
Zapier CLI would enable DRY code reuse in monorepositories by allowing import of code shared with other projects via tsconfig.json
paths
(and relative imports from outside of the Zapier project directory, as well as resolution of node_modules
libraries from the workspace root so as to not require a local node_modules
or symlink to the root node_modules
directory).