Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
abbb944
add support for ESM
haroun Jun 14, 2024
1242aac
wip
stuartromanek Aug 26, 2024
4e3ff1e
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Aug 26, 2024
182f0c6
wip
stuartromanek Aug 28, 2024
a7426f4
retry
stuartromanek Aug 28, 2024
d1ac09f
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Aug 28, 2024
bec4eec
switch promise timeout for nexttick
stuartromanek Aug 28, 2024
00b6bf2
focus considerations for media uploader
stuartromanek Aug 28, 2024
84618f1
remove logs
stuartromanek Aug 28, 2024
689304a
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 3, 2024
c4a8a64
merge
stuartromanek Sep 3, 2024
1655d34
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 4, 2024
e9df8db
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 12, 2024
e0ed87e
restore focus to last selected item after prop change
stuartromanek Sep 12, 2024
60ac86c
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 12, 2024
d721ceb
Merge remote-tracking branch 'upstream/main'
haroun Sep 16, 2024
438ca86
add import fresh
haroun Sep 16, 2024
93d22f6
use frontend as esm in test
haroun Sep 18, 2024
422dbbc
add todo
haroun Sep 18, 2024
b6c889d
remove only
haroun Sep 18, 2024
3dab529
add missing await on moog define
haroun Sep 18, 2024
31d7bc1
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 18, 2024
c7c4080
add buildRoot method and test both root in cjs and esm mode
haroun Sep 19, 2024
c4652f6
type module is required to be able to start esm mode
haroun Sep 19, 2024
5f34c91
remove unused variables
haroun Sep 19, 2024
6efc895
merge
stuartromanek Sep 19, 2024
2006a3d
expose buildRoot & getNpmPath methods
haroun Sep 19, 2024
fa3e410
test esm using npm test
haroun Sep 19, 2024
26cd0e2
"fix" aws4 missing dependency
haroun Sep 19, 2024
5b0b16a
make sure we have modal
stuartromanek Sep 19, 2024
30ee6ea
split button focus, widget priority button
stuartromanek Sep 19, 2024
9c5b8d1
use async import
haroun Sep 20, 2024
14fb03b
fix sass warnings
haroun Sep 20, 2024
1510111
async getSessionOptions
haroun Sep 20, 2024
9228577
add fallback to require
haroun Sep 20, 2024
2d12146
update workflow dependencies
haroun Sep 20, 2024
6478c53
update dev dependencies
haroun Sep 20, 2024
96a2cfe
Merge remote-tracking branch 'upstream/main'
haroun Sep 20, 2024
267c3e1
remove object.values around bundle
haroun Sep 20, 2024
90c1175
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 20, 2024
2f3388e
wip
stuartromanek Sep 23, 2024
f0ff6a7
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 23, 2024
ee12fd7
fix line
stuartromanek Sep 23, 2024
6fb3c09
lint
stuartromanek Sep 23, 2024
493416f
remove conditional rendering
stuartromanek Sep 23, 2024
fbb1042
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Sep 24, 2024
ae65582
Merge remote-tracking branch 'upstream/main'
haroun Sep 26, 2024
37b67ad
flex media manager containers
stuartromanek Oct 3, 2024
6d7eb2a
Merge branch 'main' of github.com:apostrophecms/apostrophe into PRO-4…
stuartromanek Oct 3, 2024
78fef12
Merge branch 'main' into PRO-4505/modal-priority
myovchev Oct 3, 2024
c342c08
Fix media manager not handling search results properly (sometimes)
myovchev Oct 3, 2024
6e0acaa
Merge remote-tracking branch 'upstream/main'
haroun Oct 4, 2024
0e8addf
Merge branch 'main' into PRO-4505/modal-priority
stuartromanek Oct 7, 2024
a6fb3c8
async getSessionOptions and failsafe getNpmPath
haroun Oct 8, 2024
6ed9499
fix lint issues
haroun Oct 8, 2024
deef02a
match when using coverage from nyc
haroun Oct 8, 2024
c895426
sequential getMeta
haroun Oct 8, 2024
6d9862e
allow build with esm support
haroun Oct 9, 2024
3d96187
Merge remote-tracking branch 'upstream/PRO-4505/modal-priority'
haroun Oct 9, 2024
c8ffd9d
Merge remote-tracking branch 'upstream/main'
haroun Oct 9, 2024
02bc2d8
Merge remote-tracking branch 'upstream/main'
haroun Oct 10, 2024
93e830c
clean changelog
haroun Oct 11, 2024
1af2d78
remove unrelated change data
haroun Oct 11, 2024
4b6c150
remove EOL mongo versions
haroun Oct 17, 2024
f08497f
remove package type
haroun Oct 18, 2024
90c2cbc
Merge remote-tracking branch 'upstream/main'
haroun Oct 18, 2024
0aa56e4
remove comment
haroun Oct 18, 2024
cb0ceaf
Merge remote-tracking branch 'upstream/main'
haroun Oct 22, 2024
911d8ed
getLocales and verifyLocales are now longer async
haroun Oct 23, 2024
abbf219
avoid adding .js at the end to support npm packages
haroun Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { cpus } = require('os');
const process = require('process');
const npmResolve = require('resolve');
const glob = require('glob');
const moogRequire = require('./lib/moog-require');

let defaults = require('./defaults.js');

Expand Down Expand Up @@ -293,7 +294,7 @@ async function apostrophe(options, telemetry, rootSpan) {
self.aliasEvent('modulesReady', 'modulesRegistered');
self.aliasEvent('afterInit', 'ready');

defineModules();
await defineModules();

await instantiateModules();
lintModules();
Expand Down Expand Up @@ -541,11 +542,11 @@ async function apostrophe(options, telemetry, rootSpan) {
}
}

function defineModules() {
async function defineModules() {
// Set moog-require up to create our module manager objects

self.localModules = self.options.modulesSubdir || self.options.__testLocalModules || (self.rootDir + '/modules');
const synth = require('./lib/moog-require')({
const synth = await moogRequire({
root: self.root,
bundles: [ 'apostrophe' ].concat(self.options.bundles || []),
localModules: self.localModules,
Expand All @@ -572,9 +573,9 @@ async function apostrophe(options, telemetry, rootSpan) {

nestedModuleSubdirs();

_.each(self.options.modules, function(options, name) {
synth.define(name, options);
});
for (const [ name, options ] of Object.entries(self.options.modules)) {
await synth.define(name, options);
}

// Apostrophe prefers that any improvements to @apostrophecms/global
// be applied before any project level version of @apostrophecms/global
Expand Down
32 changes: 17 additions & 15 deletions lib/moog-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const fs = require('fs');
const npmResolve = require('resolve');
const path = require('path');
const glob = require('glob');
const importFresh = require('import-fresh');
const resolveFrom = require('resolve-from');
const regExpQuote = require('regexp-quote');

module.exports = function(options) {
module.exports = async function(options) {
const self = require('./moog')(options);

if (!self.options.root) {
Expand All @@ -21,27 +20,28 @@ module.exports = function(options) {
self.improvements = {};

if (self.options.bundles) {
_.each(self.options.bundles, function(bundleName) {
for (const bundleName of Object.values(self.options.bundles)) {
const bundlePath = getNpmPath(self.root.filename, bundleName);
if (!bundlePath) {
throw 'The configured bundle ' + bundleName + ' was not found in npm.';
}
const imported = importFresh(bundlePath);
const { default: imported } = await import(bundlePath);
if (!imported.bundle) {
throw 'The configured bundle ' + bundleName + ' does not export a bundle property.';
}
const modules = imported.bundle.modules;
if (!modules) {
throw 'The configured bundle ' + bundleName + ' does not have a "modules" property within its "bundle" property.';
}
_.each(modules, function(name) {
self.bundled[name] = path.normalize(path.dirname(bundlePath) + '/' + imported.bundle.directory + '/' + name + '/index.js');
});
});
Object.values(modules)
.forEach(name => {
self.bundled[name] = path.normalize(path.dirname(bundlePath) + '/' + imported.bundle.directory + '/' + name + '/index.js');
});
}
}

const superDefine = self.define;
self.define = function(type, definition, extending) {
self.define = async function(type, definition, extending) {

let result;

Expand Down Expand Up @@ -76,7 +76,8 @@ module.exports = function(options) {
projectLevelPath = matches[0] ? path.normalize(matches[0]) : projectLevelPath;
}
if (fs.existsSync(projectLevelPath)) {
projectLevelDefinition = importFresh(resolveFrom(path.dirname(self.root.filename), projectLevelPath));
const { default: defaultProjectLevelDefinition } = await import(resolveFrom(path.dirname(self.root.filename), projectLevelPath));
projectLevelDefinition = defaultProjectLevelDefinition;
if (Object.keys(projectLevelDefinition).length === 0) {
/* eslint-disable-next-line no-console */
console.warn(`⚠️ The file ${projectLevelPath}\ndoes not export anything, did you misspell or forget module.exports?\n`);
Expand All @@ -92,7 +93,8 @@ module.exports = function(options) {

const npmPath = getNpmPath(relativeTo, type);
if (npmPath) {
npmDefinition = importFresh(npmPath);
const { default: defaultNpmDefinition } = await import(npmPath);
npmDefinition = defaultNpmDefinition;
npmDefinition.__meta = {
npm: true,
bundled: _.has(self.bundled, type),
Expand All @@ -109,8 +111,8 @@ module.exports = function(options) {
originalType = type;
type = npmDefinition.improve;
// If necessary, start by autoloading the original type
if (!self.isDefined(type, { autoload: false })) {
self.define(type);
if (!(await self.isDefined(type, { autoload: false }))) {
await self.define(type);
}
} else if (npmDefinition.replace) {
// Replace an existing type with the one defined by
Expand Down Expand Up @@ -153,14 +155,14 @@ module.exports = function(options) {
// in an implicit base class, allowing local template overrides
// even if there is no other local code
if (npmDefinition) {
result = superDefine(type, npmDefinition);
result = await superDefine(type, npmDefinition);
if (npmDefinition.improve) {
// Restore the name of the improving module as otherwise our asset chains have
// multiple references to my-foo which is ambiguous
result.__meta.name = originalType;
}
}
result = superDefine(type, definition);
result = await superDefine(type, definition);
if (npmDefinition && npmDefinition.improve) {
// Restore the name of the improving module as otherwise our asset chains have
// multiple references to my-foo which is ambiguous
Expand Down
18 changes: 9 additions & 9 deletions lib/moog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(options) {
// moog-require that need to know about relative paths. Must
// return the new definition for the convenience of moog-require too

self.define = function(className, definition, extending) {
self.define = async function(className, definition, extending) {

if (!definition) {
// This can happen because we use self.define as an autoloader
Expand Down Expand Up @@ -84,12 +84,12 @@ module.exports = function(options) {
return definition;
};

self.redefine = function(className, definition) {
self.redefine = async function(className, definition) {
delete self.definitions[className];
return self.define(className, definition);
};

self.isDefined = function(className, options) {
self.isDefined = async function(className, options) {
options = options || {};
if (_.has(self.definitions, className)) {
return true;
Expand All @@ -99,7 +99,7 @@ module.exports = function(options) {
}
try {
// Can we autoload it?
self.define(className);
await self.define(className);
// Yes, but we don't really want it yet
delete self.definitions[className];
return true;
Expand All @@ -117,7 +117,7 @@ module.exports = function(options) {
const {
that,
steps
} = createPrep(className);
} = await createPrep(className);

const options = {};

Expand Down Expand Up @@ -396,11 +396,11 @@ module.exports = function(options) {
// about modules without instantiating them fully in a release build
// environment, where database access is typically forbidden.

self.getMetadata = function(className) {
self.getMetadata = async function(className) {
const {
that,
steps
} = createPrep(className);
} = await createPrep(className);

// Now we want to start from the base class and go down
steps.reverse();
Expand Down Expand Up @@ -474,7 +474,7 @@ module.exports = function(options) {

return self;

function createPrep(className) {
async function createPrep(className) {

const that = {};
const steps = [];
Expand All @@ -500,7 +500,7 @@ module.exports = function(options) {
if (!next) {
// Try to use define as an autoloader. This will fail in
// the default implementation
next = self.define(nextName, undefined, current);
next = await self.define(nextName, undefined, current);
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions modules/@apostrophecms/asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module.exports = {
// we can access their metadata, which is sufficient
for (const name of modulesToInstantiate) {
const ancestorDirectories = [];
const metadata = self.apos.synth.getMetadata(name);
const metadata = await self.apos.synth.getMetadata(name);
for (const entry of metadata.__meta.chain) {
const effectiveName = entry.name.replace(/^my-/, '');
names[effectiveName] = true;
Expand Down Expand Up @@ -327,14 +327,14 @@ module.exports = {

let iconImports, componentImports, tiptapExtensionImports, appImports, indexJsImports, indexSassImports;
if (options.apos) {
iconImports = getIcons();
componentImports = getImports(`${source}/components`, '*.vue', {
iconImports = await getIcons();
componentImports = await getImports(`${source}/components`, '*.vue', {
registerComponents: true,
importLastVersion: true
});
/* componentImports = getGlobalVueComponents(self); */
tiptapExtensionImports = getImports(`${source}/tiptap-extensions`, '*.js', { registerTiptapExtensions: true });
appImports = getImports(`${source}/apps`, '*.js', {
tiptapExtensionImports = await getImports(`${source}/tiptap-extensions`, '*.js', { registerTiptapExtensions: true });
appImports = await getImports(`${source}/apps`, '*.js', {
invokeApps: true,
enumerateImports: true,
importSuffix: 'App'
Expand All @@ -350,15 +350,15 @@ module.exports = {
[entry.name]: true
}), {});

indexJsImports = getImports(source, 'index.js', {
indexJsImports = await getImports(source, 'index.js', {
invokeApps: true,
enumerateImports: true,
importSuffix: 'App',
requireDefaultExport: true,
mainModuleBundles: getMainModuleBundleFiles('js'),
ignoreModules
});
indexSassImports = getImports(source, 'index.scss', {
indexSassImports = await getImports(source, 'index.scss', {
importSuffix: 'Stylesheet',
enumerateImports: true,
mainModuleBundles: getMainModuleBundleFiles('scss'),
Expand Down Expand Up @@ -459,7 +459,7 @@ module.exports = {
//
// Of course, developers can push an "public" asset that is
// the output of an ES6 pipeline.
const publicImports = getImports(name, '*.js');
const publicImports = await getImports(name, '*.js');
fs.writeFileSync(`${bundleDir}/${name}-build.js`,
(((options.prologue || '') + '\n') || '') +
publicImports.paths.map(path => {
Expand All @@ -468,7 +468,7 @@ module.exports = {
);
}
if (options.outputs.includes('css')) {
const publicImports = getImports(name, '*.css');
const publicImports = await getImports(name, '*.css');
fs.writeFileSync(`${bundleDir}/${name}-build.css`,
publicImports.paths.map(path => {
return self.filterCss(fs.readFileSync(path, 'utf8'), {
Expand Down Expand Up @@ -548,9 +548,9 @@ module.exports = {
);
}

function getIcons() {
async function getIcons() {
for (const name of modulesToInstantiate) {
const metadata = self.apos.synth.getMetadata(name);
const metadata = await self.apos.synth.getMetadata(name);
// icons is an unparsed section, so getMetadata gives it back
// to us as an object with a property for each class in the
// inheritance tree, root first. Just keep merging in
Expand Down Expand Up @@ -690,11 +690,11 @@ module.exports = {
return fs.copyFile(from, to);
}

function getImports(folder, pattern, options = {}) {
async function getImports(folder, pattern, options = {}) {
let components = [];
const seen = {};
for (const name of modulesToInstantiate) {
const metadata = self.apos.synth.getMetadata(name);
const metadata = await self.apos.synth.getMetadata(name);
for (const entry of metadata.__meta.chain) {
if (options.ignoreModules?.[entry.name]) {
seen[entry.dirname] = true;
Expand Down
3 changes: 1 addition & 2 deletions modules/@apostrophecms/asset/lib/webpack/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ module.exports = {
async getWebpackExtensions ({
getMetadata, modulesToInstantiate, rebundleModulesConfig = {}
}) {
const modulesMeta = modulesToInstantiate
.map((name) => getMetadata(name));
const modulesMeta = await Promise.all(modulesToInstantiate.map((name) => getMetadata(name)));

const rebundleModules = formatRebundleConfig(rebundleModulesConfig);

Expand Down