Skip to content

Commit 3edd006

Browse files
authored
PRO-6050 fix all deprecation warnings that can reasonably be fixed at this time without bc issues (#4576)
* fix all deprecation warnings that can reasonably be fixed at this time without bc issues * uploadfs 1.22.4 * stray logs * new uses of cuid crept in * reorder * oops * call sort() explicitly to emulate former behavior of glob, should address failing regression tests * match the sorting semantics exactly
1 parent 7400640 commit 3edd006

35 files changed

+123
-100
lines changed

index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const cluster = require('cluster');
99
const { cpus } = require('os');
1010
const process = require('process');
1111
const npmResolve = require('resolve');
12-
const glob = require('glob');
13-
12+
const glob = require('./lib/glob.js');
1413
let defaults = require('./defaults.js');
1514

1615
// ## Top-level options
@@ -389,7 +388,7 @@ async function apostrophe(options, telemetry, rootSpan) {
389388
if (!options.nestedModuleSubdirs) {
390389
return;
391390
}
392-
const configs = glob.sync(self.localModules + '/**/modules.js', { follow: true });
391+
const configs = glob(self.localModules + '/**/modules.js', { follow: true });
393392
_.each(configs, function(config) {
394393
try {
395394
_.merge(self.options.modules, require(config));

lib/glob.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { globSync } = require('glob');
2+
3+
// synchronous glob 10 but with the sorting semantics of glob 8,
4+
// to ease backwards compatibility in Apostrophe startup logic
5+
6+
module.exports = (pattern, options) => {
7+
const result = globSync(pattern, options);
8+
if (!options.nosort) {
9+
result.sort((a, b) => a.localeCompare(b, 'en'));
10+
}
11+
return result;
12+
};

lib/moog-require.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const _ = require('lodash');
22
const fs = require('fs');
33
const npmResolve = require('resolve');
44
const path = require('path');
5-
const glob = require('glob');
5+
const glob = require('./glob.js');
66
const importFresh = require('import-fresh');
77
const resolveFrom = require('resolve-from');
88
const regExpQuote = require('regexp-quote');
@@ -60,7 +60,7 @@ module.exports = function(options) {
6060
// Fetching a list of index.js files on the first call and then searching it each time for
6161
// one that refers to the right type name shaves as much as 60 seconds off the startup
6262
// time in a large project, compared to using the glob cache feature
63-
self._indexes = glob.sync(self.options.localModules + '/**/index.js', { follow: true });
63+
self._indexes = glob(self.options.localModules + '/**/index.js', { follow: true });
6464
}
6565
const matches = self._indexes.filter(function(index) {
6666
// Double-check that we're not confusing "@apostrophecms/asset" with "asset" by
@@ -255,7 +255,7 @@ module.exports = function(options) {
255255
// Ternary is required because glob expects at least 2 entries when using curly braces
256256
const pattern = workspaces.length === 1 ? workspaces[0] : `{${workspaces.join(',')}}`;
257257
const packagePath = path.resolve(folder, pattern, 'package.json');
258-
const workspacePackages = glob.sync(packagePath, { follow: true });
258+
const workspacePackages = glob(packagePath, { follow: true });
259259

260260
return workspacePackages.flatMap(packagePath => {
261261
const info = JSON.parse(fs.readFileSync(packagePath, 'utf8'));

modules/@apostrophecms/admin-bar/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// takes advantage of this module.
66

77
const _ = require('lodash');
8-
const cuid = require('cuid');
8+
const { createId } = require('@paralleldrive/cuid2');
99

1010
module.exports = {
1111
options: {
@@ -353,7 +353,7 @@ module.exports = {
353353
contextBar: context && self.apos.doc.getManager(context.type).options.contextBar,
354354
// Simplifies frontend logic
355355
contextId: context && context._id,
356-
tabId: cuid(),
356+
tabId: createId(),
357357
contextEditorName,
358358
pageTree: self.options.pageTree && self.apos.permission.can(req, 'edit', '@apostrophecms/any-page-type', 'draft'),
359359
bars: self.bars,

modules/@apostrophecms/admin-bar/ui/apos/components/TheAposContextBar.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<script>
3737
import { klona } from 'klona';
38-
import cuid from 'cuid';
38+
import { createId } from '@paralleldrive/cuid2';
3939
import AposPublishMixin from 'Modules/@apostrophecms/ui/mixins/AposPublishMixin';
4040
import AposAdvisoryLockMixin from 'Modules/@apostrophecms/ui/mixins/AposAdvisoryLockMixin';
4141
@@ -159,7 +159,7 @@ export default {
159159
// sessionStorage because it is deliberately browser-tab specific
160160
let tabId = sessionStorage.getItem('aposTabId');
161161
if (!tabId) {
162-
tabId = cuid();
162+
tabId = createId();
163163
sessionStorage.setItem('aposTabId', tabId);
164164
}
165165
window.apos.adminBar.tabId = tabId;

modules/@apostrophecms/area/ui/apos/components/AposAreaContextualMenu.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</template>
8383

8484
<script>
85-
import cuid from 'cuid';
85+
import { createId } from '@paralleldrive/cuid2';
8686
8787
export default {
8888
name: 'AposAreaContextualMenu',
@@ -184,7 +184,7 @@ export default {
184184
}
185185
},
186186
menuId() {
187-
return `areaMenu-${cuid()}`;
187+
return `areaMenu-${createId()}`;
188188
}
189189
},
190190
mounted() {

modules/@apostrophecms/area/ui/apos/components/AposAreaEditor.vue

+6-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</template>
7171

7272
<script>
73-
import cuid from 'cuid';
73+
import { createId } from '@paralleldrive/cuid2';
7474
import { klona } from 'klona';
7575
import AposThemeMixin from 'Modules/@apostrophecms/ui/mixins/AposThemeMixin';
7676
@@ -148,7 +148,7 @@ export default {
148148
addWidgetEditor: null,
149149
addWidgetOptions: null,
150150
addWidgetType: null,
151-
areaId: cuid(),
151+
areaId: createId(),
152152
next: this.getValidItems(),
153153
hoveredWidget: null,
154154
hoveredNonForeignWidget: null,
@@ -406,7 +406,7 @@ export default {
406406
// Regenerate all array item, area, object and widget ids so they are considered
407407
// new. Useful when copying a widget with nested content.
408408
regenerateIds(schema, object) {
409-
object._id = cuid();
409+
object._id = createId();
410410
for (const field of schema) {
411411
if (field.type === 'array') {
412412
for (const item of (object[field.name] || [])) {
@@ -416,7 +416,7 @@ export default {
416416
this.regenerateIds(field.schema, object[field.name] || {});
417417
} else if (field.type === 'area') {
418418
if (object[field.name]) {
419-
object[field.name]._id = cuid();
419+
object[field.name]._id = createId();
420420
for (const item of (object[field.name].items || [])) {
421421
const schema = apos.modules[apos.area.widgetManagers[item.type]].schema;
422422
this.regenerateIds(schema, item);
@@ -513,7 +513,7 @@ export default {
513513
},
514514
async insert({ index, widget }) {
515515
if (!widget._id) {
516-
widget._id = cuid();
516+
widget._id = createId();
517517
}
518518
if (!widget.metaType) {
519519
widget.metaType = 'widget';
@@ -600,7 +600,7 @@ export default {
600600
schema.forEach(field => {
601601
if (field.type === 'area') {
602602
widget[field.name] = {
603-
_id: cuid(),
603+
_id: createId(),
604604
metaType: 'area',
605605
items: []
606606
};

modules/@apostrophecms/asset/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const glob = require('glob');
21
const fs = require('fs-extra');
32
const Promise = require('bluebird');
43
const webpackModule = require('webpack');
@@ -8,7 +7,7 @@ const util = require('util');
87
const express = require('express');
98
const { stripIndent } = require('common-tags');
109
const { mergeWithCustomize: webpackMerge } = require('webpack-merge');
11-
const cuid = require('cuid');
10+
const { createId } = require('@paralleldrive/cuid2');
1211
const chokidar = require('chokidar');
1312
const _ = require('lodash');
1413
const {
@@ -110,7 +109,7 @@ module.exports = {
110109
components(self) {
111110
return {
112111
scripts(req, data) {
113-
const placeholder = `[scripts-placeholder:${cuid()}]`;
112+
const placeholder = `[scripts-placeholder:${createId()}]`;
114113

115114
req.scriptsPlaceholder = placeholder;
116115

@@ -119,7 +118,7 @@ module.exports = {
119118
};
120119
},
121120
stylesheets(req, data) {
122-
const placeholder = `[stylesheets-placeholder:${cuid()}]`;
121+
const placeholder = `[stylesheets-placeholder:${createId()}]`;
123122

124123
req.stylesheetsPlaceholder = placeholder;
125124

@@ -247,7 +246,7 @@ module.exports = {
247246
const scenes = [ ...new Set(Object.values(self.builds).map(options => options.scenes).flat()) ];
248247

249248
// enumerate public assets and include them in deployment if appropriate
250-
const publicAssets = glob.sync('modules/**/*', {
249+
const publicAssets = self.apos.util.glob('modules/**/*', {
251250
cwd: bundleDir,
252251
mark: true
253252
}).filter(match => !match.endsWith('/'));
@@ -702,7 +701,7 @@ module.exports = {
702701
if (seen[entry.dirname]) {
703702
continue;
704703
}
705-
components = components.concat(glob.sync(`${entry.dirname}/ui/${folder}/${pattern}`));
704+
components = components.concat(self.apos.util.glob(`${entry.dirname}/ui/${folder}/${pattern}`));
706705
seen[entry.dirname] = true;
707706
}
708707
}

modules/@apostrophecms/doc/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const _ = require('lodash');
2-
const cuid = require('cuid');
2+
const { createId } = require('@paralleldrive/cuid2');
33
const { SemanticAttributes } = require('@opentelemetry/semantic-conventions');
44
const { klona } = require('klona');
55

@@ -1696,7 +1696,7 @@ module.exports = {
16961696
}
16971697
for (const widget of area.items || []) {
16981698
if ((!widget._id) || seen.has(widget._id)) {
1699-
widget._id = cuid();
1699+
widget._id = createId();
17001700
} else {
17011701
seen.add(widget._id);
17021702
}

modules/@apostrophecms/i18n/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ module.exports = {
595595
// if the appropriate query parameters were set, rewrite
596596
// `_id` accordingly. Returns `_id`, after rewriting if appropriate.
597597
inferIdLocaleAndMode(req, _id) {
598-
let [ cuid, locale, mode ] = _id.split(':');
598+
let [ id, locale, mode ] = _id.split(':');
599599
if (locale && mode) {
600600
if (!req.query.aposLocale) {
601601
req.locale = locale;
@@ -621,7 +621,7 @@ module.exports = {
621621
// will be interpreted later
622622
return _id;
623623
} else {
624-
return `${cuid}:${locale}:${mode}`;
624+
return `${id}:${locale}:${mode}`;
625625
}
626626
},
627627
getBrowserData(req) {

modules/@apostrophecms/image/ui/apos/components/AposMediaManager.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
import { debounce } from 'Modules/@apostrophecms/ui/utils';
129129
import AposModifiedMixin from 'Modules/@apostrophecms/ui/mixins/AposModifiedMixin';
130130
import AposDocsManagerMixin from 'Modules/@apostrophecms/modal/mixins/AposDocsManagerMixin';
131-
import cuid from 'cuid';
131+
import { createId } from '@paralleldrive/cuid2';
132132

133133
const DEBOUNCE_TIMEOUT = 500;
134134

@@ -350,7 +350,7 @@ export default {
350350
},
351351
createPlaceholder(dimensions) {
352352
this.items.unshift({
353-
_id: cuid(),
353+
_id: createId(),
354354
title: 'placeholder image',
355355
dimensions
356356
});

modules/@apostrophecms/image/ui/apos/components/AposMediaManagerDisplay.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</template>
9292

9393
<script>
94-
import cuid from 'cuid';
94+
import { createId } from '@paralleldrive/cuid2';
9595
9696
export default {
9797
// Custom model to handle the v-model connection on the parent.
@@ -207,7 +207,7 @@ export default {
207207
event.target.classList.remove('apos-is-hovering');
208208
},
209209
idFor(item) {
210-
return `${item._id}-${cuid()}`;
210+
return `${item._id}-${createId()}`;
211211
}
212212
}
213213
};

modules/@apostrophecms/image/ui/apos/components/AposMediaManagerEditor.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ import { klona } from 'klona';
112112
import dayjs from 'dayjs';
113113
import { isEqual } from 'lodash';
114114
import advancedFormat from 'dayjs/plugin/advancedFormat';
115-
import cuid from 'cuid';
115+
import { createId } from '@paralleldrive/cuid2';
116116
117117
dayjs.extend(advancedFormat);
118118
@@ -344,7 +344,7 @@ export default {
344344
}
345345
},
346346
generateLipKey() {
347-
this.lipKey = cuid();
347+
this.lipKey = createId();
348348
},
349349
cancel() {
350350
this.showReplace = false;

modules/@apostrophecms/login/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
const Passport = require('passport').Passport;
4242
const LocalStrategy = require('passport-local');
4343
const Promise = require('bluebird');
44-
const cuid = require('cuid');
44+
const { createId } = require('@paralleldrive/cuid2');
4545
const expressSession = require('express-session');
4646

4747
const loginAttemptsNamespace = '@apostrophecms/loginAttempt';
@@ -774,7 +774,7 @@ module.exports = {
774774

775775
const requirementsToVerify = Object.keys(lateRequirements);
776776
if (requirementsToVerify.length) {
777-
const token = cuid();
777+
const token = createId();
778778

779779
await self.bearerTokens.insertOne({
780780
_id: token,
@@ -802,7 +802,7 @@ module.exports = {
802802
});
803803
return {};
804804
} else {
805-
const token = cuid();
805+
const token = createId();
806806
await self.bearerTokens.insertOne({
807807
_id: token,
808808
userId: user._id,

modules/@apostrophecms/modal/ui/apos/components/AposModalShareDraft.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,6 @@ export default {
322322
margin-top: $spacing-double;
323323
color: var(--a-primary);
324324
text-decoration: none;
325-
font-weight: var(--a-weight-bold);;
325+
font-weight: var(--a-weight-bold);
326326
}
327327
</style>

modules/@apostrophecms/modal/ui/apos/mixins/AposDocErrorsMixin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cuid from 'cuid';
1+
import { createId } from '@paralleldrive/cuid2';
22

33
export default {
44
data: () => ({
@@ -19,7 +19,7 @@ export default {
1919
},
2020
methods: {
2121
updateFieldErrors(fieldState) {
22-
this.tabKey = cuid();
22+
this.tabKey = createId();
2323
for (const key in this.groups) {
2424
this.groups[key].fields.forEach(field => {
2525
if (fieldState[field]) {

modules/@apostrophecms/modal/ui/apos/mixins/AposModalTabsMixin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import cuid from 'cuid';
1+
import { createId } from '@paralleldrive/cuid2';
22

33
// Provide basic bridging functionality between tabs
44
// and the modal body.
55

66
export default {
77
data() {
88
return {
9-
tabKey: cuid(),
9+
tabKey: createId(),
1010
currentTab: null
1111
};
1212
},

modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AposModifiedMixin from 'Modules/@apostrophecms/ui/mixins/AposModifiedMixin';
22
import AposEditorMixin from 'Modules/@apostrophecms/modal/mixins/AposEditorMixin';
3-
import cuid from 'cuid';
3+
import { createId } from '@paralleldrive/cuid2';
44
import { klona } from 'klona';
55
import { get } from 'lodash';
66
import { detectDocChange } from 'Modules/@apostrophecms/schema/lib/detectChange';
@@ -42,7 +42,7 @@ export default {
4242
// Automatically add `_id` to default items
4343
const items = this.items.map(item => ({
4444
...item,
45-
_id: item._id || cuid()
45+
_id: item._id || createId()
4646
}));
4747

4848
return {
@@ -195,7 +195,7 @@ export default {
195195
async add() {
196196
if (await this.validate(true, false)) {
197197
const item = this.newInstance();
198-
item._id = cuid();
198+
item._id = createId();
199199
this.next.push(item);
200200
await this.select(item._id);
201201
this.updateMinMax();

0 commit comments

Comments
 (0)