Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion packages/build_kolibri_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ function rebuildApiSpec() {
};
writeSourceToFile(kolibriPackageJsonFilePath, JSON.stringify(updatedKolibriPackageJson, null, 2));
const apiSpecFilePath = path.resolve(__dirname, './kolibri/internal/apiSpec.js');
const updatedApiKeys = generateApiKeys(updatedKolibriPackageJson.exports);
const updatedApiKeys = generateApiKeys(
updatedKolibriPackageJson.exports,
updatedKolibriPackageJson.exposes || [],
);
let apiSpecContent = apiSpecHeader;
apiSpecContent += 'export default {\n';
for (const key of updatedApiKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const _ = require('lodash');
const webpackConfigPlugin = require('../webpack.config.plugin');

jest.mock('../apiSpecExportTools', () => ({
coreAliases: () => ({}),
coreExternals: () => ({}),
getCoreExternals: () => ({}),
}));

jest.mock('kolibri-logging', () => ({
Expand Down
33 changes: 18 additions & 15 deletions packages/kolibri-build/src/apiSpecExportTools.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const kolibriPackageJson = require('kolibri/package.json');

const apiSpec = kolibriPackageJson.exports || {};

const { kolibriName } = require('./kolibriName');

function generateApiKeys(apiSpec) {
function generateApiKeys(apiSpec, exposes) {
// Generate a list of all the module imports that we need to expose
// Iterate over all the exports in the kolibri package
return (
Expand All @@ -17,23 +13,30 @@ function generateApiKeys(apiSpec) {
.map(key => 'kolibri' + key.slice(1))
// Add the list of modules that are exposed in the kolibri package.json
// Unmodified, as they are already full import paths, e.g. 'vue'
.concat(kolibriPackageJson.exposes)
.concat(exposes)
);
}

const apiKeys = generateApiKeys(apiSpec);
function getCoreExternals() {
const kolibriPackageJson = require('kolibri/package.json');

const coreExternals = {
// The kolibri package itself is a special case, as it is the root of the package
// and is not required to be imported in the core bundle, as it is the core bundle.
kolibri: kolibriName,
};
const apiSpec = kolibriPackageJson.exports || {};

const apiKeys = generateApiKeys(apiSpec, kolibriPackageJson.exposes || []);

const coreExternals = {
// The kolibri package itself is a special case, as it is the root of the package
// and is not required to be imported in the core bundle, as it is the core bundle.
kolibri: kolibriName,
};

for (const key of apiKeys) {
coreExternals[key] = [kolibriName, key];
for (const key of apiKeys) {
coreExternals[key] = [kolibriName, key];
}
return coreExternals;
}

module.exports = {
coreExternals,
getCoreExternals,
generateApiKeys,
};
4 changes: 2 additions & 2 deletions packages/kolibri-build/src/webpack.config.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const logging = require('kolibri-logging');
const BundleTracker = require('./webpackBundleTracker');
const baseConfig = require('./webpack.config.base');
const { coreExternals } = require('./apiSpecExportTools');
const { getCoreExternals } = require('./apiSpecExportTools');
const WebpackRTLPlugin = require('./webpackRtlPlugin');
const { kolibriName } = require('./kolibriName');
const WebpackMessages = require('./webpackMessages');
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = (
const isCoreBundle = webpackConfig.output && webpackConfig.output.library === kolibriName;

// If this is not the core bundle, then we need to add the external library mappings.
const externals = isCoreBundle ? {} : coreExternals;
const externals = isCoreBundle ? {} : getCoreExternals();

const alias = {};
if (kdsPath) {
Expand Down