This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: replace nanoid with randomId util
When linking local-components for development use, our use of nanoid causes the error below, preventing the app from loading. Our options to fix this seem to be to: 1. Downgrade from nanoid 5 to 3: ai/nanoid#422 (comment) 2. Refactor to use a dynamic import (potentially infecting all call sites with `await` and refactoring to make parent functions async). 3. Switch from "module": "commonjs" to "module": "ESNext" and assess the impact of that change. 4. Remove nanoid and create a simple randomId function instead. I went with (4). We don't need the full hardware-random IDs that nanoid provides, and we only used nanoid in one component. nanoid error in getflywheel-local after running nps components.link and nps.build, then opening the app: require() of ES Module /Users/nick.cernis/localdev/local-components/node_modules/nanoid/index.js from /Users/nick.cernis/localdev/local-components/dist/index.js not supported. Instead change the require of /Users/nick.cernis/localdev/local-components/node_modules/nanoid/index.js in /Users/nick.cernis/localdev/local-components/dist/index.js to a dynamic import() which is available in all CommonJS modules.
- Loading branch information
1 parent
3980d92
commit c53a75e
Showing
5 changed files
with
16 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Creates a random URL-safe string for IDs and unique fallback values. | ||
* | ||
* @param len Length of the string to generate. | ||
*/ | ||
export default function randomId(len: number = 21): string { | ||
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; | ||
let result = ''; | ||
for (let i = 0; i < len; i += 1) { | ||
const randomIndex = Math.floor(Math.random() * charset.length); | ||
result += charset[randomIndex]; | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters