Skip to content

Commit

Permalink
Fix: Use nanonid/non-secure instead of cuid (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatkashyap authored Apr 25, 2023
1 parent 854056d commit 7cc2496
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"csstype": "^3.1.2",
"cuid": "^3.0.0",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"esbuild": "0.17.18",
Expand All @@ -101,6 +100,7 @@
"mime": "^3.0.0",
"monaco-editor": "0.37.1",
"mysql2": "^3.2.3",
"nanoid": "^4.0.2",
"next": "^13.3.1",
"node-fetch": "^2.6.9",
"node-fetch-har": "^1.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/toolpad-app/src/appDom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from 'nanoid/non-secure';
import { generateKeyBetween } from 'fractional-indexing';
import cuid from 'cuid';
import {
NodeId,
NodeReference,
Expand Down Expand Up @@ -234,8 +234,8 @@ function assertIsType<T extends AppDomNode>(node: AppDomNode, type: T['type']):
invariant(isType(node, type), `Expected node type "${type}" but got "${node.type}"`);
}

function createId(): NodeId {
return cuid.slug() as NodeId;
export function createId(): NodeId {
return nanoid(7) as NodeId;
}

export function createConst<V>(value: V): ConstantAttrValue<V> {
Expand Down
4 changes: 2 additions & 2 deletions packages/toolpad-app/src/components/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react';
import * as monaco from 'monaco-editor';
import { styled, SxProps } from '@mui/material';
import clsx from 'clsx';
import cuid from 'cuid';
import { nanoid } from 'nanoid/non-secure';
import invariant from 'invariant';
import {
conf as jsonBasicConf,
Expand Down Expand Up @@ -370,7 +370,7 @@ export default React.forwardRef<MonacoEditorHandle, MonacoEditorProps>(function
}
}
} else {
const pathUri = monaco.Uri.parse(`./scripts/${cuid()}${getExtension(language)}`);
const pathUri = monaco.Uri.parse(`./scripts/${nanoid(7)}${getExtension(language)}`);
const model = monaco.editor.createModel(value || '', language, pathUri);

instance = monaco.editor.create(rootRef.current, {
Expand Down
3 changes: 1 addition & 2 deletions packages/toolpad-app/src/server/localMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { fromZodError } from 'zod-validation-error';
import { glob } from 'glob';
import * as chokidar from 'chokidar';
import { debounce } from 'lodash-es';
import cuid from 'cuid';
import { Emitter } from '@mui/toolpad-utils/events';
import { errorFrom } from '@mui/toolpad-utils/errors';
import { filterValues, hasOwnProperty, mapValues } from '@mui/toolpad-utils/collections';
Expand Down Expand Up @@ -1108,7 +1107,7 @@ async function initToolpadFolder(root: string) {
apiVersion: 'v1',
kind: 'page',
spec: {
id: cuid.slug(),
id: appDom.createId(),
title: 'Default page',
},
};
Expand Down
10 changes: 9 additions & 1 deletion packages/toolpad-app/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export default defineConfig([
},
outDir: 'dist/cli',
silent: true,
noExternal: ['open-editor', 'execa', 'fractional-indexing', 'lodash-es', 'chalk', 'get-port'],
noExternal: [
'open-editor',
'execa',
'fractional-indexing',
'lodash-es',
'chalk',
'get-port',
'nanoid',
],
clean: true,
sourcemap: true,
async onSuccess() {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4931,11 +4931,6 @@ csstype@^3.0.2, csstype@^3.1.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

cuid@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cuid/-/cuid-3.0.0.tgz#8cef32136e3c48e4a94aec42025996b888cbae82"
integrity sha512-WZYYkHdIDnaxdeP8Misq3Lah5vFjJwGuItJuV+tvMafosMzw0nF297T7mrm8IOWiPJkV6gc7sa8pzx27+w25Zg==

"d3-array@2 - 3", "d3-array@2.10.0 - 3", d3-array@^3.1.6:
version "3.2.3"
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-3.2.3.tgz#39f1f4954e4a09ff69ac597c2d61906b04e84740"
Expand Down Expand Up @@ -9593,6 +9588,11 @@ nanoid@^3.3.4, nanoid@^3.3.6:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==

nanoid@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-4.0.2.tgz#140b3c5003959adbebf521c170f282c5e7f9fb9e"
integrity sha512-7ZtY5KTCNheRGfEFxnedV5zFiORN1+Y1N6zvPTnHQd8ENUvfaDBeuJDZb2bN/oXwXxu3qkTXDzy57W5vAmDTBw==

natural-compare-lite@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4"
Expand Down

0 comments on commit 7cc2496

Please sign in to comment.