Skip to content

Commit

Permalink
Fix type resolution when using moduleResolution node16 (#7284)
Browse files Browse the repository at this point in the history
Type resolution is broken for node16 resolution type due to several
issues, this PR:

- Updates all relative imports to include .js file extension, as
required by node16 resolution
- Includes type declaration files from lib folder in package publish
- Adds package.json file to `lib` folder to indicate contents are
commonjs
- Updates package exports field to point to the appropriate type
declaration files for ESM or CJS
- Adds browser and node subpaths to msal-common export to separate
node-only and browser-only features

Fixes #6781 #6487 #6269

---------

Co-authored-by: Hector Morales <[email protected]>
  • Loading branch information
tnorling and hectormmg authored Sep 19, 2024
1 parent 330e807 commit 5a68dbb
Show file tree
Hide file tree
Showing 275 changed files with 6,906 additions and 17,069 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix type resolution when using moduleResolution node16",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix type resolution when using moduleResolution node16",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix type resolution when using moduleResolution node16",
"packageName": "@azure/msal-node",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix type resolution when using moduleResolution node16",
"packageName": "@azure/msal-node-extensions",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix type resolution when using moduleResolution node16",
"packageName": "@azure/msal-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions extensions/msal-node-extensions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Generated files
build
dist
lib

# Logs
test/test-logs
Expand Down
21 changes: 14 additions & 7 deletions extensions/msal-node-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
"url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
},
"license": "MIT",
"type": "module",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"main": "lib/msal-node-extensions.cjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./lib/types/index.d.ts",
"default": "./lib/msal-node-extensions.cjs"
}
},
"./package.json": "./package.json"
},
Expand All @@ -28,15 +33,16 @@
],
"files": [
"dist",
"bin"
"bin",
"lib"
],
"engines": {
"node": ">=16"
},
"scripts": {
"compile": "node-gyp rebuild",
"install": "exit 0",
"clean": "shx rm -rf dist bin",
"clean": "shx rm -rf dist bin lib",
"build": "npm run clean && rollup -c --strictDeprecations --bundleConfigAsCjs && node ./scripts/buildBinaries.cjs",
"build:all": "cd ../.. && npm run build --workspace=@azure/msal-common --workspace=@azure/msal-node-extensions",
"test": "jest",
Expand Down Expand Up @@ -71,6 +77,7 @@
"jest": "^29.5.0",
"node-addon-api": "^6.1.0",
"rollup": "^3.20.2",
"rollup-msal": "file:../../shared-configs/rollup-msal",
"shx": "^0.3.4",
"ts-jest": "^29.1.0",
"ts-jest-mock-import-meta": "^1.1.0",
Expand Down
13 changes: 7 additions & 6 deletions extensions/msal-node-extensions/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import pkg from "./package.json";
import { createPackageJson } from "rollup-msal";

const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${new Date().toISOString().split("T")[0]} */`;
const useStrictHeader = "'use strict';";
Expand All @@ -16,11 +17,9 @@ export default [
// for cjs build
input: "src/index.ts",
output: {
dir: "dist",
dir: "lib",
format: "cjs",
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].cjs",
entryFileNames: "msal-node-extensions.cjs",
banner: fileHeader,
sourcemap: true
},
Expand All @@ -36,11 +35,13 @@ export default [
plugins: [
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.build.json"
tsconfig: "tsconfig.build.json",
compilerOptions: { outDir: "lib/types" }
}),
nodeResolve({
preferBuiltins: true
})
}),
createPackageJson({libPath: __dirname})
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
PromptValue,
ServerError,
ServerTelemetryManager,
} from "@azure/msal-common";
} from "@azure/msal-common/node";
import {
msalNodeRuntime,
Account,
Expand All @@ -36,9 +36,9 @@ import {
SignOutResult,
LogLevel as MsalRuntimeLogLevel,
} from "@azure/msal-node-runtime";
import { ErrorCodes } from "../utils/Constants";
import { NativeAuthError } from "../error/NativeAuthError";
import { version, name } from "../packageMetadata";
import { ErrorCodes } from "../utils/Constants.js";
import { NativeAuthError } from "../error/NativeAuthError.js";
import { version, name } from "../packageMetadata.js";

export class NativeBrokerPlugin implements INativeBrokerPlugin {
private logger: Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { AuthError } from "@azure/msal-common";
import { AuthError } from "@azure/msal-common/node";

export class NativeAuthError extends AuthError {
public statusCode: number;
Expand Down
24 changes: 12 additions & 12 deletions extensions/msal-node-extensions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Licensed under the MIT License.
*/

export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
export { FilePersistence } from "./persistence/FilePersistence";
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
export { DataProtectionScope } from "./persistence/DataProtectionScope";
export { KeychainPersistence } from "./persistence/KeychainPersistence";
export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
export { IPersistence } from "./persistence/IPersistence";
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
export { PersistenceCreator } from "./persistence/PersistenceCreator";
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
export { Environment } from "./utils/Environment";
export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin";
export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin.js";
export { FilePersistence } from "./persistence/FilePersistence.js";
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection.js";
export { DataProtectionScope } from "./persistence/DataProtectionScope.js";
export { KeychainPersistence } from "./persistence/KeychainPersistence.js";
export { LibSecretPersistence } from "./persistence/LibSecretPersistence.js";
export { IPersistence } from "./persistence/IPersistence.js";
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions.js";
export { PersistenceCreator } from "./persistence/PersistenceCreator.js";
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration.js";
export { Environment } from "./utils/Environment.js";
export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin.js";
10 changes: 5 additions & 5 deletions extensions/msal-node-extensions/src/lock/CrossPlatformLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { promises as fs } from "fs";
import { pid } from "process";
import { CrossPlatformLockOptions } from "./CrossPlatformLockOptions";
import { Constants } from "../utils/Constants";
import { PersistenceError } from "../error/PersistenceError";
import { Logger } from "@azure/msal-common";
import { isNodeError } from "../utils/TypeGuards";
import { CrossPlatformLockOptions } from "./CrossPlatformLockOptions.js";
import { Constants } from "../utils/Constants.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { Logger } from "@azure/msal-common/node";
import { isNodeError } from "../utils/TypeGuards.js";

/**
* Cross-process lock that works on all platforms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License.
*/

import { PersistenceError } from "../error/PersistenceError";
import { Constants } from "../utils/Constants";
import { IPersistence } from "./IPersistence";
import { PersistenceError } from "../error/PersistenceError.js";
import { Constants } from "../utils/Constants.js";
import { IPersistence } from "./IPersistence.js";

export abstract class BasePersistence {
public abstract createForPersistenceValidation(): Promise<IPersistence>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import { promises as fs } from "fs";
import { dirname } from "path";
import { IPersistence } from "./IPersistence";
import { Constants, ErrorCodes } from "../utils/Constants";
import { PersistenceError } from "../error/PersistenceError";
import { Logger, LoggerOptions, LogLevel } from "@azure/msal-common";
import { BasePersistence } from "./BasePersistence";
import { isNodeError } from "../utils/TypeGuards";
import { IPersistence } from "./IPersistence.js";
import { Constants, ErrorCodes } from "../utils/Constants.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { Logger, LoggerOptions, LogLevel } from "@azure/msal-common/node";
import { BasePersistence } from "./BasePersistence.js";
import { isNodeError } from "../utils/TypeGuards.js";

/**
* Reads and writes data to file specified by file location. File contents are not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Licensed under the MIT License.
*/

import { IPersistence } from "./IPersistence";
import { FilePersistence } from "./FilePersistence";
import { PersistenceError } from "../error/PersistenceError";
import { Dpapi } from "../Dpapi";
import { DataProtectionScope } from "./DataProtectionScope";
import { Logger, LoggerOptions } from "@azure/msal-common";
import { IPersistence } from "./IPersistence.js";
import { FilePersistence } from "./FilePersistence.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { Dpapi } from "../Dpapi.js";
import { DataProtectionScope } from "./DataProtectionScope.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { dirname } from "path";
import { BasePersistence } from "./BasePersistence";
import { isNodeError } from "../utils/TypeGuards";
import { BasePersistence } from "./BasePersistence.js";
import { isNodeError } from "../utils/TypeGuards.js";

/**
* Uses CryptProtectData and CryptUnprotectData on Windows to encrypt and decrypt file contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { Logger } from "@azure/msal-common";
import { Logger } from "@azure/msal-common/node";

export interface IPersistence {
save(contents: string): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License.
*/

import type { LoggerOptions } from "@azure/msal-common";
import type { LoggerOptions } from "@azure/msal-common/node";

import { DataProtectionScope } from "./DataProtectionScope";
import { DataProtectionScope } from "./DataProtectionScope.js";

export interface IPersistenceConfiguration {
cachePath?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

import keytar from "keytar";
import { FilePersistence } from "./FilePersistence";
import { IPersistence } from "./IPersistence";
import { PersistenceError } from "../error/PersistenceError";
import { Logger, LoggerOptions } from "@azure/msal-common";
import { FilePersistence } from "./FilePersistence.js";
import { IPersistence } from "./IPersistence.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { dirname } from "path";
import { BasePersistence } from "./BasePersistence";
import { isNodeError } from "../utils/TypeGuards";
import { BasePersistence } from "./BasePersistence.js";
import { isNodeError } from "../utils/TypeGuards.js";

/**
* Uses reads and writes passwords to macOS keychain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

import keytar from "keytar";
import { FilePersistence } from "./FilePersistence";
import { IPersistence } from "./IPersistence";
import { PersistenceError } from "../error/PersistenceError";
import { Logger, LoggerOptions } from "@azure/msal-common";
import { FilePersistence } from "./FilePersistence.js";
import { IPersistence } from "./IPersistence.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { dirname } from "path";
import { BasePersistence } from "./BasePersistence";
import { isNodeError } from "../utils/TypeGuards";
import { BasePersistence } from "./BasePersistence.js";
import { isNodeError } from "../utils/TypeGuards.js";

/**
* Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
* Licensed under the MIT License.
*/

import { IPersistence } from "./IPersistence";
import { CrossPlatformLock } from "../lock/CrossPlatformLock";
import { CrossPlatformLockOptions } from "../lock/CrossPlatformLockOptions";
import { IPersistence } from "./IPersistence.js";
import { CrossPlatformLock } from "../lock/CrossPlatformLock.js";
import { CrossPlatformLockOptions } from "../lock/CrossPlatformLockOptions.js";
import { pid } from "process";
import { TokenCacheContext, ICachePlugin, Logger } from "@azure/msal-common";
import {
TokenCacheContext,
ICachePlugin,
Logger,
} from "@azure/msal-common/node";

/**
* MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Licensed under the MIT License.
*/

import { FilePersistenceWithDataProtection } from "./FilePersistenceWithDataProtection";
import { LibSecretPersistence } from "./LibSecretPersistence";
import { KeychainPersistence } from "./KeychainPersistence";
import { DataProtectionScope } from "./DataProtectionScope";
import { Environment } from "../utils/Environment";
import { IPersistence } from "./IPersistence";
import { FilePersistence } from "./FilePersistence";
import { PersistenceError } from "../error/PersistenceError";
import { IPersistenceConfiguration } from "./IPersistenceConfiguration";
import { FilePersistenceWithDataProtection } from "./FilePersistenceWithDataProtection.js";
import { LibSecretPersistence } from "./LibSecretPersistence.js";
import { KeychainPersistence } from "./KeychainPersistence.js";
import { DataProtectionScope } from "./DataProtectionScope.js";
import { Environment } from "../utils/Environment.js";
import { IPersistence } from "./IPersistence.js";
import { FilePersistence } from "./FilePersistence.js";
import { PersistenceError } from "../error/PersistenceError.js";
import { IPersistenceConfiguration } from "./IPersistenceConfiguration.js";

export class PersistenceCreator {
static async createPersistence(
Expand Down
4 changes: 2 additions & 2 deletions extensions/msal-node-extensions/src/utils/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import path from "path";
import { Constants, Platform } from "./Constants";
import { PersistenceError } from "../error/PersistenceError";
import { Constants, Platform } from "./Constants.js";
import { PersistenceError } from "../error/PersistenceError.js";

export class Environment {
static get homeEnvVar(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function runMultipleProcesses(
let count = 0;
for (let i = 0; i < numProcesses; i++) {
const proc = fork(
"./test/performance-test/LockAndWriteToStorageScript.js",
"./test/performance-test/LockAndWriteToStorageScript.cjs",
options
);
proc.on("exit", (code) => {
Expand Down
Loading

0 comments on commit 5a68dbb

Please sign in to comment.