Skip to content

Commit

Permalink
feat: ACNA-3098 - allow action invocation of ES Modules / Typescript (#…
Browse files Browse the repository at this point in the history
…87)

* use dist folder (webpacked action source)
* add ESM action, Typescript action
* fix jsdoc
* add eslint config
* support DUMP_PARAMS input
* add comment regarding ts-loader
* add source-map output for webpack, add .vscode/launch.json
* remove cached webpacked code
* use aio-lib-runtime to build the app
* add actions watcher
* update README
* fix unit tests
* mock actionsWatcher
* completed 100% coverage
* specify version of @adobe/aio-lib-runtime for buildActions emptyDist param
* run-dev tests code cleanup
* fixed actions-watcher tests leaks
* fix: require.cache cleanup, always build latest
* require aio-lib-runtime with optimized builds

---------

Co-authored-by: Jesse MacFadyen <purplecabbage@gmail.com>
  • Loading branch information
shazron and purplecabbage authored Sep 27, 2024
1 parent 65d1190 commit 98d4e2a
Show file tree
Hide file tree
Showing 21 changed files with 1,087 additions and 110 deletions.
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-cli-plugin-app-dev/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-cli-plugin-app-dev/)

This command is a new way of looking at local development.
This uses the approach of a simulator, rather than an emulator.

<!-- toc -->
* [aio-cli-plugin-app-dev](#aio-cli-plugin-app-dev)
<!-- tocstop -->
- This command is a new way of looking at local development. This uses the approach of a simulator, rather than an emulator.
- Supports ESM, and TypeScript actions.
- [App Builder Debugging Docs](https://developer.adobe.com/app-builder/docs/guides/development/#debugging)

## Commands
<!-- commands -->
* [`aio app dev`](#aio-app-dev)
- [`aio app dev`](#aio-app-dev)

## `aio app dev`

Run your App Builder app locally

```
```sh
USAGE
$ aio app dev [-v] [--version] [-o] [-e <value>]

Expand All @@ -48,6 +45,58 @@ By default the hostname will be `localhost` and the default port is `9080`. You
The command will try to use the default port, if it is not available it will find an open port to use instead.
## Visual Studio Code Webpack Debugging Support (Source Maps)
To enable step-by-step debugging in Visual Studio Code for your webpacked code, you will have to add source map support by adding a [custom webpack config](https://developer.adobe.com/app-builder/docs/guides/configuration/webpack-configuration/).
In the root of your project, add a `webpack-config.js` file:
```javascript
module.exports = {
devtool: 'inline-source-map'
}
```
## TypeScript Support
Install these node modules in your app:
`npm install --save-dev ts-loader typescript`
In the root of your project, add a `webpack-config.js` file:
```javascript
module.exports = {
devtool: 'inline-source-map',
module: {
rules: [
{
// includes, excludes are in tsconfig.json
test: /\.ts?$/,
exclude: /node_modules/,
use: 'ts-loader'
}
]
}
}
```
In the root of your project, add a `tsconfig.json` file:
```json
{
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"sourceMap": true
}
}
```
There is a Visual Studio Code issue with TypeScript and inspecting variables by hovering your mouse over them:
<https://github.com/microsoft/vscode/issues/221503>
## Contributing
Contributions are welcomed! Read the [Contributing Guide](CONTRIBUTING.md) for more information.
Expand Down
10 changes: 10 additions & 0 deletions e2e/test-project/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"settings": {
"jsdoc": {
"ignorePrivate": true
}
},
"parserOptions": {
"ecmaVersion": "latest"
}
}
31 changes: 31 additions & 0 deletions e2e/test-project/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "0.3.0",
"configurations": [
{
"name": "App Builder: debug actions",
"type": "node-terminal",
"request": "launch",
"command": "aio app dev",
"skipFiles": [
"<node_internals>/**/*.js"
]
}, {
"name": "App Builder: debug full stack",
"type": "node-terminal",
"request": "launch",
"command": "aio app dev",
"sourceMapPathOverrides": {
"/__parcel_source_root/*": "${webRoot}/*"
},
"skipFiles": [
"<node_internals>/**/*.js"
],
"serverReadyAction": {
"pattern": "server running on port : ([0-9]+)",
"uriFormat": "https://localhost:%s",
"action": "debugWithChrome",
"webRoot": "${workspaceFolder}"
}
}
]
}
2 changes: 2 additions & 0 deletions e2e/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"regenerator-runtime": "^0.13.5"
},
"devDependencies": {
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"@babel/core": "^7.8.7",
"@babel/plugin-transform-react-jsx": "^7.8.3",
"@babel/polyfill": "^7.8.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function addNumbers (params) {
const sum = nums.reduce((accum, num) => accum + parseInt(num.trim(), 10), 0)
return {
payload: sum, // to be passed to other actions in the sequence as part of params
body: {
body: {
payload: sum // sent to the http client for a stand-alone call
}
}
Expand Down
26 changes: 26 additions & 0 deletions e2e/test-project/src/dx-excshell-1/actions/esmAction/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

/**
* The main function.
*
* @param {object} params the parameters
* @returns {object} runtime response object
*/
export async function main (params) {
const response = {
statusCode: 200,
params,
body: 'you were successful with esm'
}
return response
}
25 changes: 23 additions & 2 deletions e2e/test-project/src/dx-excshell-1/actions/post-data/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
async function main(params) {
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

/**
* The main function.
*
* @param {object} params the parameters
* @returns {object} runtime response object
*/
async function main (params) {
if (params.DUMP_PARAMS) {
console.log('params', JSON.stringify(params, null, 2))
}
const response = {
statusCode: 200,
body: {
Expand All @@ -7,4 +28,4 @@ async function main(params) {
}
return response
}
exports.main = main
exports.main = main
26 changes: 24 additions & 2 deletions e2e/test-project/src/dx-excshell-1/actions/post-raw-data/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
async function main(params) {
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

/**
* The main function.
*
* @param {object} params the parameters
* @returns {object} runtime response object
*/
async function main (params) {
if (params.DUMP_PARAMS) {
console.log('params', JSON.stringify(params, null, 2))
}

const response = {
statusCode: 200,
body: {
Expand All @@ -7,4 +29,4 @@ async function main(params) {
}
return response
}
exports.main = main
exports.main = main
25 changes: 25 additions & 0 deletions e2e/test-project/src/dx-excshell-1/actions/tsAction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

/**
* The main function.
*
* @returns {object} runtime response object
*/
export function main(params: object) {
const response = {
statusCode: 200,
params,
body: 'you were successful with typescript'
}
return response
}
18 changes: 18 additions & 0 deletions e2e/test-project/src/dx-excshell-1/ext.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ runtimeManifest:
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
DUMP_PARAMS: $DUMP_PARAMS
annotations:
final: true
post-raw-data:
Expand All @@ -50,6 +51,7 @@ runtimeManifest:
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
DUMP_PARAMS: $DUMP_PARAMS
annotations:
final: true
noAdobeAuth:
Expand Down Expand Up @@ -124,3 +126,19 @@ runtimeManifest:
LOG_LEVEL: debug
annotations:
final: true
esmAction:
function: actions/esmAction/index.js
web: 'yes'
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
annotations:
final: true
tsAction:
function: actions/tsAction/index.ts
web: 'yes'
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
annotations:
final: true
2 changes: 2 additions & 0 deletions e2e/test-project/src/dx-excshell-1/web-src/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dx-excshell-1/throwsError": "https://localhost:9080/api/v1/web/dx-excshell-1/throwsError",
"dx-excshell-1/noResponseObject": "https://localhost:9080/api/v1/web/dx-excshell-1/noResponseObject",
"dx-excshell-1/actionIsNonWeb": "https://localhost:9080/api/v1/dx-excshell-1/actionIsNonWeb",
"dx-excshell-1/esmAction": "https://localhost:9080/api/v1/web/dx-excshell-1/esmAction",
"dx-excshell-1/tsAction": "https://localhost:9080/api/v1/web/dx-excshell-1/tsAction",
"dx-excshell-1/nonWebSequence": "https://localhost:9080/api/v1/dx-excshell-1/nonWebSequence",
"dx-excshell-1/sequenceWithAllActionsAvailable": "https://localhost:9080/api/v1/web/dx-excshell-1/sequenceWithAllActionsAvailable",
"dx-excshell-1/sequenceWithActionThatThrowsError": "https://localhost:9080/api/v1/web/dx-excshell-1/sequenceWithActionThatThrowsError",
Expand Down
4 changes: 4 additions & 0 deletions e2e/test-project/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"include": ["src/dx-excshell-1/actions/tsAction"],
"exclude": ["node_modules", "dist"]
}
17 changes: 11 additions & 6 deletions e2e/test-project/webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

module.exports = {
devtool: 'source-map',
module: {
rules: [
{
test: /tsAction\/index.ts$/,
// includes, excludes are in tsconfig.json
use: 'ts-loader'
},
{
test: /syntaxidermist\/index.js$/,
use: [
Expand All @@ -11,9 +16,9 @@ module.exports = {
name: '__index.js',
emitFile: true
}
},
],
},
],
},
}
]
}
]
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"@adobe/aio-lib-core-config": "^5",
"@adobe/aio-lib-core-logging": "^3",
"@adobe/aio-lib-env": "^3",
"@adobe/aio-lib-runtime": "^6",
"@adobe/aio-lib-runtime": "^7.0.0",
"@adobe/aio-lib-web": "^7",
"@oclif/core": "^3",
"chalk": "^4",
"chokidar": "^3.6.0",
"connect-livereload": "^0.6.1",
"execa": "^5.0.0",
"express": "^4.18.2",
Expand All @@ -27,7 +28,8 @@
"livereload": "^0.9.3",
"lodash.clonedeep": "^4.5.0",
"open": "^8.4.2",
"ora": "^5"
"ora": "^5",
"upath": "^2.0.1"
},
"devDependencies": {
"@adobe/aio-lib-core-networking": "^5",
Expand Down
Loading

0 comments on commit 98d4e2a

Please sign in to comment.