Skip to content

Commit 8d86a79

Browse files
web: Fix failing web mode due to fs-extra import (aws#5248)
* docs: Update web mode docs - Add information about a common error so that developers can hopefully ctrl+f this when debugging - Remove the more complex image of dependency cruiser as it just causes confusion Signed-off-by: Nikolas Komonen <[email protected]> * web: make 'common' codewhisperer export module Problem: When importing the codewhisperer exports module from index.ts in web mode it was breaking due to a transitive fs-extra import. Solution: Export a separate module from indexCommon.ts for code that works in web or node. This file is a subset of index.ts, so behavior remains the same. Signed-off-by: Nikolas Komonen <[email protected]> --------- Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 494ff1d commit 8d86a79

File tree

6 files changed

+25
-776
lines changed

6 files changed

+25
-776
lines changed

docs/images/dependency-graph.svg

Lines changed: 0 additions & 768 deletions
This file was deleted.

docs/web.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ If you need to manage npm modules required for Web mode, such as a [browserfied
9292
For example, if I have a Typescript module, `myFile.ts`, that imports a module which imports another module (transitive dependency) such as `fs-extra`,
9393
when I execute `myFile.ts` in the browser it will break due to `fs-extra` not being browser compatible.
9494

95+
> INFO: A common error is `Cannot read properties of undefined (reading 'native')` caused by `fs-extra`
96+
9597
It may be difficult to determine which module imported `fs-extra` due to a nested chain of transitive dependencies.
9698

9799
As a solution, we can use [`dependency-cruiser`](https://www.npmjs.com/package/dependency-cruiser) to generate a dependency diagram
@@ -102,10 +104,11 @@ to help us visualize the imports and determine which module is importing a certa
102104
1. Install the `graphviz` cli, this provides the `dot` cli command
103105
- Mac: `brew install graphviz`
104106
- Others: [See documentation](https://www.graphviz.org/download/)
105-
2. Run `npx depcruise {RELATIVE_PATH_TO_FILE} --output-type dot | dot -T svg > dependency-graph.svg`
106-
- For example, `npx depcruise src/srcShared/fs.ts --output-type dot | dot -T svg > dependency-graph.svg` generates the following which shows `fs-extra` is imported by `fileSystemUtilities.ts`:
107-
![Dependency Graph](./images/dependency-graph.svg)
108-
- Additionally specify a certain dependency with `--reaches` , `npx depcruise src/srcShared/fs.ts --reaches "fs-extra" --output-type dot | dot -T svg > dependency-graph.svg`, to hide unrelated dependencies:
107+
2. Temporarily install `dependency-cruiser`
108+
- IMPORTANT: You will want to revert this install when done
109+
- `npm i dependency-cruiser`
110+
3. Run `npx depcruise {RELATIVE_PATH_TO_FILE} --reaches "{YOUR_MODULE}" --output-type dot | dot -T svg > dependency-graph.svg`
111+
- For example `npx depcruise src/srcShared/fs.ts --reaches "fs-extra" --output-type dot | dot -T svg > dependency-graph.svg`, generates the following which shows that `fs-extra` is imported by `fileSystemUtilities.ts`:
109112
![Dependency Graph](./images/dependency-graph-small.svg)
110113

111114
## Behavior of module exports in tests

packages/amazonq/src/extensionCommon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
shutdown as shutdownCodeWhisperer,
1212
amazonQDismissedKey,
1313
AuthUtil,
14-
} from 'aws-core-vscode/codewhisperer'
14+
} from 'aws-core-vscode/codewhispererCommon'
1515
import {
1616
ExtContext,
1717
initialize,

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"./common": "./dist/src/common/index.js",
3535
"./amazonq": "./dist/src/amazonq/index.js",
3636
"./codewhisperer": "./dist/src/codewhisperer/index.js",
37+
"./codewhispererCommon": "./dist/src/codewhisperer/indexCommon.js",
3738
"./shared": "./dist/src/shared/index.js",
3839
"./srcShared": "./dist/src/srcShared/index.js",
3940
"./auth": "./dist/src/auth/index.js",

packages/core/src/codewhisperer/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export { activate, shutdown } from './activation'
7-
export * from './util/authUtil'
6+
export * from './indexCommon'
7+
88
export * from './models/model'
99
export * as model from './models/model'
10-
export * from './models/constants'
1110
export * as CodeWhispererConstants from './models/constants'
1211
export * from './commands/basicCommands'
1312
export * from './commands/types'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* This module is a subset of `./index.js` except it is for 'common' code only.
8+
*
9+
* See "Shared vs Common" in our docs/ folder for the meaning of 'common'
10+
*/
11+
12+
export { activate, shutdown } from './activation'
13+
export * from './util/authUtil'
14+
export * from './models/constants'

0 commit comments

Comments
 (0)