Skip to content

Commit

Permalink
Add "inlineDynamicImports" to rollup config to fix CJS build. Make fa…
Browse files Browse the repository at this point in the history
…ctory methods basic functions (#6615)

- Add "inlineDynamicImports" to rollup config to fix CJS build.
- Make factory methods basic functions.
  • Loading branch information
konstantin-msft authored Oct 30, 2023
1 parent a8e0c73 commit 9296e4b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add \"inlineDynamicImports\" to rollup config to fix CJS build. Make factory methods basic functions #6615",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
53 changes: 28 additions & 25 deletions lib/msal-browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import pkg from "./package.json";

const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${new Date().toISOString().split("T")[0]} */`;
const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${
new Date().toISOString().split("T")[0]
} */`;
const useStrictHeader = "'use strict';";
const fileHeader = `${libraryHeader}\n${useStrictHeader}`;

Expand All @@ -27,18 +29,18 @@ export default [
},
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false
propertyReadSideEffects: false,
},
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.build.json"
})
]
tsconfig: "tsconfig.build.json",
}),
],
},
{
input: "src/index.ts",
Expand All @@ -49,21 +51,22 @@ export default [
format: "cjs",
banner: fileHeader,
sourcemap: true,
entryFileNames: "msal-browser.cjs"
entryFileNames: "msal-browser.cjs",
inlineDynamicImports: true,
},
],
plugins: [
nodeResolve({
browser: true,
resolveOnly: ["@azure/msal-common", "tslib"]
resolveOnly: ["@azure/msal-common", "tslib"],
}),
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.build.json",
sourceMap: true,
compilerOptions: { outDir: "./lib" }
})
]
compilerOptions: { outDir: "./lib" },
}),
],
},
{
input: "src/index.ts",
Expand All @@ -76,21 +79,21 @@ export default [
banner: fileHeader,
inlineDynamicImports: true,
sourcemap: true,
entryFileNames: "msal-browser.js"
}
entryFileNames: "msal-browser.js",
},
],
plugins: [
nodeResolve({
browser: true,
resolveOnly: ["@azure/msal-common", "tslib"]
resolveOnly: ["@azure/msal-common", "tslib"],
}),
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.build.json",
sourceMap: true,
compilerOptions: { outDir: "./lib" }
})
]
compilerOptions: { outDir: "./lib" },
}),
],
},
{
// Minified version of msal
Expand All @@ -104,24 +107,24 @@ export default [
banner: useStrictHeader,
inlineDynamicImports: true,
sourcemap: false,
}
},
],
plugins: [
nodeResolve({
browser: true,
resolveOnly: ["@azure/msal-common", "tslib"]
resolveOnly: ["@azure/msal-common", "tslib"],
}),
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.build.json",
sourceMap: false,
compilerOptions: { outDir: "./lib" }
compilerOptions: { outDir: "./lib" },
}),
terser({
output: {
preamble: libraryHeader
}
})
]
}
preamble: libraryHeader,
},
}),
],
},
];
7 changes: 4 additions & 3 deletions lib/msal-browser/src/app/PublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "@azure/msal-common";
import { EndSessionRequest } from "../request/EndSessionRequest";
import { SsoSilentRequest } from "../request/SsoSilentRequest";
import { ControllerFactory } from "../controllers/ControllerFactory";
import * as ControllerFactory from "../controllers/ControllerFactory";
import { StandardController } from "../controllers/StandardController";
import { BrowserConfiguration, Configuration } from "../config/Configuration";
import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
Expand All @@ -38,8 +38,9 @@ export class PublicClientApplication implements IPublicClientApplication {
public static async createPublicClientApplication(
configuration: Configuration
): Promise<IPublicClientApplication> {
const factory = new ControllerFactory(configuration);
const controller = await factory.createV3Controller();
const controller = await ControllerFactory.createV3Controller(
configuration
);
const pca = new PublicClientApplication(configuration, controller);

return pca;
Expand Down
12 changes: 7 additions & 5 deletions lib/msal-browser/src/app/PublicClientNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "@azure/msal-common";
import { EndSessionRequest } from "../request/EndSessionRequest";
import { SsoSilentRequest } from "../request/SsoSilentRequest";
import { ControllerFactory } from "../controllers/ControllerFactory";
import * as ControllerFactory from "../controllers/ControllerFactory";
import { BrowserConfiguration, Configuration } from "../config/Configuration";
import { EventCallbackFunction } from "../event/EventMessage";
import { ClearCacheRequest } from "../request/ClearCacheRequest";
Expand All @@ -47,8 +47,9 @@ export class PublicClientNext implements IPublicClientApplication {
public static async createPublicClientApplication(
configuration: Configuration
): Promise<IPublicClientApplication> {
const factory = new ControllerFactory(configuration);
const controller = await factory.createController();
const controller = await ControllerFactory.createController(
configuration
);
let pca;
if (controller !== null) {
pca = new PublicClientNext(configuration, controller);
Expand Down Expand Up @@ -100,8 +101,9 @@ export class PublicClientNext implements IPublicClientApplication {
*/
async initialize(): Promise<void> {
if (this.controller instanceof UnknownOperatingContextController) {
const factory = new ControllerFactory(this.configuration);
const result = await factory.createController();
const result = await ControllerFactory.createController(
this.configuration
);
if (result !== null) {
this.controller = result;
}
Expand Down
79 changes: 30 additions & 49 deletions lib/msal-browser/src/controllers/ControllerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,42 @@
import { TeamsAppOperatingContext } from "../operatingcontext/TeamsAppOperatingContext";
import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
import { IController } from "./IController";
import { Logger } from "@azure/msal-common";
import { Configuration } from "../config/Configuration";
import { version, name } from "../packageMetadata";

export class ControllerFactory {
protected config: Configuration;
protected logger: Logger;
export async function createV3Controller(
config: Configuration
): Promise<IController> {
const standard = new StandardOperatingContext(config);

constructor(config: Configuration) {
this.config = config;
const loggerOptions = {
loggerCallback: undefined,
piiLoggingEnabled: false,
logLevel: undefined,
correlationId: undefined,
};
this.logger = new Logger(loggerOptions, name, version);
}

async createV3Controller(): Promise<IController> {
const standard = new StandardOperatingContext(this.config);
await standard.initialize();

await standard.initialize();
const controller = await import("./StandardController");
return await controller.StandardController.createController(standard);
}

export async function createController(
config: Configuration
): Promise<IController | null> {
const standard = new StandardOperatingContext(config);
const teamsApp = new TeamsAppOperatingContext(config);

const operatingContexts = [standard.initialize(), teamsApp.initialize()];

await Promise.all(operatingContexts);

if (
teamsApp.isAvailable() &&
teamsApp.getConfig().auth.supportsNestedAppAuth
) {
const controller = await import("./NestedAppAuthController");
return await controller.NestedAppAuthController.createController(
teamsApp
);
} else if (standard.isAvailable()) {
const controller = await import("./StandardController");
return await controller.StandardController.createController(standard);
}

async createController(): Promise<IController | null> {
const standard = new StandardOperatingContext(this.config);
const teamsApp = new TeamsAppOperatingContext(this.config);

const operatingContexts = [
standard.initialize(),
teamsApp.initialize(),
];

await Promise.all(operatingContexts);

if (
teamsApp.isAvailable() &&
teamsApp.getConfig().auth.supportsNestedAppAuth
) {
const controller = await import("./NestedAppAuthController");
return await controller.NestedAppAuthController.createController(
teamsApp
);
} else if (standard.isAvailable()) {
const controller = await import("./StandardController");
return await controller.StandardController.createController(
standard
);
} else {
// Since neither of the actual operating contexts are available keep the UnknownOperatingContextController
return null;
}
} else {
// Since neither of the actual operating contexts are available keep the UnknownOperatingContextController
return null;
}
}

0 comments on commit 9296e4b

Please sign in to comment.