Skip to content

Commit

Permalink
fix: remove schematic takes care of missing props
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Sep 22, 2024
1 parent feaecbd commit fb06cd9
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 118 deletions.
2 changes: 1 addition & 1 deletion libs/mf-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@angular-architects/module-federation-runtime",
"license": "MIT",
"version": "18.0.4",
"version": "18.0.5",
"peerDependencies": {
"@angular/common": ">=18.0.0",
"@angular/core": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion libs/mf-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular-architects/module-federation-tools",
"version": "18.0.4",
"version": "18.0.5",
"license": "MIT",
"peerDependencies": {},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions libs/mf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular-architects/module-federation",
"version": "18.0.4",
"version": "18.0.5",
"license": "MIT",
"repository": {
"type": "GitHub",
Expand All @@ -17,7 +17,7 @@
"schematics": "./collection.json",
"builders": "./builders.json",
"dependencies": {
"@angular-architects/module-federation-runtime": "18.0.4",
"@angular-architects/module-federation-runtime": "18.0.5",
"word-wrap": "^1.2.3",
"callsite": "^1.0.0",
"node-fetch": "^2.6.7",
Expand Down
15 changes: 9 additions & 6 deletions libs/mf/src/schematics/remove/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ function updateServeConfig(normalized: {
delete serve.options.extraWebpackConfig;
delete serve.options.customWebpackConfig;

const serveProd = serve.configurations.production;
delete serveProd.extraWebpackConfig;
delete serveProd.customWebpackConfig;
const serveProd = serve?.configurations?.production;

if (serveProd) {
delete serveProd.extraWebpackConfig;
delete serveProd.customWebpackConfig;
}
const prodTarget = serveProd?.browserTarget;

const prodTarget = serveProd.browserTarget;
if (prodTarget) {
delete serveProd.browserTarget;
serveProd.buildTarget = prodTarget;
}

const serveDev = serve.configurations.development;
const devTarget = serveDev.browserTarget;
const serveDev = serve?.configurations?.development;
const devTarget = serveDev?.browserTarget;

if (devTarget) {
delete serveDev.browserTarget;
Expand Down
2 changes: 1 addition & 1 deletion libs/native-federation-node/build/create-data-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const dataUrl = `data:text/javascript;base64,${base64Content}`;
const outputPath = path.resolve(__dirname, dataUrlFile);
fs.writeFileSync(outputPath, `export const resolver = "${base64Content}";\n`);

console.log('Created data url for loader');
console.log('Created data url for loader');

This file was deleted.

11 changes: 0 additions & 11 deletions libs/native-federation-node/src/lib/node/import-map-store.ts.bak

This file was deleted.

45 changes: 23 additions & 22 deletions libs/native-federation-node/src/lib/utils/import-map-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// https://raw.githubusercontent.com/node-loader/
//

import path from "path";
import url from "url";
import { promises as fs } from "fs";
import path from 'path';
import url from 'url';
import { promises as fs } from 'fs';

export const IMPORT_MAP_FILE_NAME = "node.importmap";
export const IMPORT_MAP_FILE_NAME = 'node.importmap';

const baseURL = url.pathToFileURL(process.cwd()) + path.sep;

Expand All @@ -25,7 +25,7 @@ export function resolveSpecifier(importMap, specifier, parentURL) {
for (let scopePrefix in importMap.scopes) {
if (
scopePrefix === currentBaseURL ||
(scopePrefix.endsWith("/") && currentBaseURL.startsWith(scopePrefix))
(scopePrefix.endsWith('/') && currentBaseURL.startsWith(scopePrefix))
) {
const scopeImportsMatch = resolveImportsMatch(
normalizedSpecifier,
Expand Down Expand Up @@ -61,7 +61,7 @@ function resolveImportsMatch(normalizedSpecifier, specifierMap) {
}
return resolutionResult;
} else if (
specifierKey.endsWith("/") &&
specifierKey.endsWith('/') &&
normalizedSpecifier.startsWith(specifierKey)
) {
if (resolutionResult === null) {
Expand Down Expand Up @@ -94,7 +94,7 @@ export function resolveAndComposeImportMap(parsed) {
let sortedAndNormalizedImports = {};

// Step 4
if (parsed.hasOwnProperty("imports")) {
if (parsed.hasOwnProperty('imports')) {
// Step 4.1
if (!isPlainObject(parsed.imports)) {
throw Error(`Invalid import map - "imports" property must be an object`);
Expand All @@ -111,7 +111,7 @@ export function resolveAndComposeImportMap(parsed) {
let sortedAndNormalizedScopes = {};

// Step 6
if (parsed.hasOwnProperty("scopes")) {
if (parsed.hasOwnProperty('scopes')) {
// Step 6.1
if (!isPlainObject(parsed.scopes)) {
throw Error(`Invalid import map - "scopes" property must be an object`);
Expand All @@ -123,13 +123,13 @@ export function resolveAndComposeImportMap(parsed) {

// Step 7
const invalidKeys = Object.keys(parsed).filter(
(key) => key !== "imports" && key !== "scopes"
(key) => key !== 'imports' && key !== 'scopes'
);
if (invalidKeys.length > 0) {
console.warn(
`Invalid top-level key${
invalidKeys.length > 0 ? "s" : ""
} in import map - ${invalidKeys.join(", ")}`
invalidKeys.length > 0 ? 's' : ''
} in import map - ${invalidKeys.join(', ')}`
);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ function sortAndNormalizeSpecifierMap(map, baseURL) {
continue;
}

if (specifierKey.endsWith("/") && !addressURL.endsWith("/")) {
if (specifierKey.endsWith('/') && !addressURL.endsWith('/')) {
console.warn(
`Invalid URL address for import map specifier '${specifierKey}' - since the specifier ends in slash, so must the address`
);
Expand All @@ -177,7 +177,7 @@ function sortAndNormalizeSpecifierMap(map, baseURL) {

// https://wicg.github.io/import-maps/#normalize-a-specifier-key
function normalizeSpecifierKey(key) {
if (key === "") {
if (key === '') {
console.warn(`Specifier keys in import maps may not be the empty string`);
return null;
}
Expand All @@ -188,9 +188,9 @@ function normalizeSpecifierKey(key) {
// https://wicg.github.io/import-maps/#parse-a-url-like-import-specifier
function parseURLLikeSpecifier(specifier, baseURL) {
const useBaseUrlAsParent =
specifier.startsWith("/") ||
specifier.startsWith("./") ||
specifier.startsWith("../");
specifier.startsWith('/') ||
specifier.startsWith('./') ||
specifier.startsWith('../');

try {
return new URL(specifier, useBaseUrlAsParent ? baseURL : undefined).href;
Expand Down Expand Up @@ -236,21 +236,23 @@ function isPlainObject(obj) {

// ---


let importMapPromise = getImportMapPromise();

export async function resolve(specifier, context, defaultResolve) {
const { parentURL = null } = context;
const importMap = await importMapPromise;
let importMapUrl = resolveSpecifier(importMap, specifier, parentURL);

if (importMapUrl?.startsWith('http://') || importMapUrl?.startsWith('https://')) {
if (
importMapUrl?.startsWith('http://') ||
importMapUrl?.startsWith('https://')
) {
importMapUrl = await cacheBundle(importMapUrl);
}

const r = defaultResolve(importMapUrl ?? specifier, context, defaultResolve);

return r.then(r => {
return r.then((r) => {
return { ...r, format: 'module' };
});
}
Expand All @@ -259,7 +261,7 @@ async function cacheBundle(importMapUrl) {
const fileName = importMapUrl.replace(/[^a-zA-Z0-9.]/g, '_');
const filePath = path.join('./cache', fileName);

if (!await exists(filePath)) {
if (!(await exists(filePath))) {
const res = await fetch(importMapUrl);
const source = await res.text();
await ensureCacheFolder();
Expand All @@ -271,7 +273,7 @@ async function cacheBundle(importMapUrl) {
}

async function ensureCacheFolder() {
if (!await exists('./cache')) {
if (!(await exists('./cache'))) {
await fs.mkdir('./cache');
}
}
Expand Down Expand Up @@ -321,7 +323,6 @@ function emptyMap() {
return { imports: {}, scopes: {} };
}


async function exists(path) {
try {
await fs.access(path);
Expand Down
Loading

0 comments on commit fb06cd9

Please sign in to comment.