diff --git a/.vscode/launch.json b/.vscode/launch.json index 2301813a7..dcbf59852 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -54,7 +54,7 @@ "program": "${workspaceRoot}/tools/buildsystem/bin/buildsystem.ts", "args": [ "-n", - "build" + "package" ], "cwd": "${workspaceRoot}", "preLaunchTask": "build-buildsystem", diff --git a/buildsystem-config.ts b/buildsystem-config.ts index aa08ff7b7..1c84a727b 100644 --- a/buildsystem-config.ts +++ b/buildsystem-config.ts @@ -28,17 +28,34 @@ const logLevel = LogLevel.Verbose; const distFolder = "./dist/packages"; const commonPublishTags = ["--access", "public"]; -function PnPBuild(): (b: BuildTimeline) => BuildTimeline { +function PnPBuild(buildFlags?: string[]): (b: BuildTimeline) => BuildTimeline { return (instance: BuildTimeline) => { - Build()(instance); + Build(buildFlags)(instance); ReplaceVersion(["sp/behaviors/telemetry.js", "graph/behaviors/telemetry.js"])(instance); return instance; } } +function PnPBuildCommonJS(buildFlags?: string[]): (b: BuildTimeline) => BuildTimeline { + + if (!buildFlags) { + buildFlags = []; + } + + buildFlags.push("--module", "commonjs", "--outDir", "./buildcjs") + + return (instance: BuildTimeline) => { + + Build(buildFlags)(instance); + ReplaceVersion([resolve("./buildcjs/packages/sp/behaviors/telemetry.js"), resolve("./buildcjs/packages/graph/behaviors/telemetry.js")], { pathsResolved: true })(instance); + + return instance; + } +} + function PnPPackage(): (b: BuildTimeline) => BuildTimeline { return (instance: BuildTimeline) => { @@ -90,7 +107,7 @@ const commonBehaviors = [ PnPLogging(logLevel), ] -export default [{ +export default [{ name: "build", distFolder, targets: [ @@ -112,7 +129,7 @@ export default [{ targets: [ resolve("./packages/tsconfig.json"), ], - behaviors: [PnPBuild(), PnPPackage(), ...commonBehaviors], + behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), ...commonBehaviors], }, { name: "publish", @@ -120,7 +137,7 @@ export default [{ targets: [ resolve("./packages/tsconfig.json"), ], - behaviors: [PnPBuild(), PnPPackage(), PnPPublish(commonPublishTags), ...commonBehaviors], + behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), PnPPublish(commonPublishTags), ...commonBehaviors], }, { name: "publish-beta", @@ -128,7 +145,7 @@ export default [{ targets: [ resolve("./packages/tsconfig.json"), ], - behaviors: [PnPBuild(), PnPPackage(), PnPPublish([...commonPublishTags, "--tag", "beta"]), ...commonBehaviors], + behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), PnPPublish([...commonPublishTags, "--tag", "beta"]), ...commonBehaviors], }, { name: "publish-v3nightly", @@ -144,5 +161,5 @@ export default [{ targets: [ resolve("./packages/tsconfig.json"), ], - behaviors: [PnPBuild(), PnPPackage(), PublishNightly([...commonPublishTags], "v4nightly"), ...commonBehaviors], + behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), PublishNightly([...commonPublishTags], "v4nightly"), ...commonBehaviors], }]; diff --git a/tools/buildsystem/index.ts b/tools/buildsystem/index.ts index 422bc1949..38095fb4d 100644 --- a/tools/buildsystem/index.ts +++ b/tools/buildsystem/index.ts @@ -4,7 +4,7 @@ export { CopyAssetFiles } from "./src/behaviors/copy-asset-files.js"; export { CopyPackageFiles } from "./src/behaviors/copy-package-files.js"; export { PublishNightly } from "./src/behaviors/publish-nightly.js"; export { Publish } from "./src/behaviors/publish.js"; -export { ReplaceVersion } from "./src/behaviors/replace-version.js"; +export { ReplaceVersion, IReplaceVersionOptions } from "./src/behaviors/replace-version.js"; export { Webpack } from "./src/behaviors/webpack.js"; export { WritePackageJSON } from "./src/behaviors/write-packagejson.js"; diff --git a/tools/buildsystem/package-lock.json b/tools/buildsystem/package-lock.json index 54fe8ced9..213de9055 100644 --- a/tools/buildsystem/package-lock.json +++ b/tools/buildsystem/package-lock.json @@ -1,15 +1,15 @@ { "name": "@pnp/buildsystem", - "version": "4.0.0-beta3", + "version": "4.0.0-beta5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pnp/buildsystem", - "version": "4.0.0-beta3", + "version": "4.0.0-beta5", "license": "MIT", "dependencies": { - "@pnp/core": "^3.21.0", + "@pnp/core": "^4.0.0-alpha0-v4nightly.20231227", "globby": "^14.0.0", "liftoff": "^4.0.0", "webpack": "^5.89.0", @@ -153,9 +153,9 @@ } }, "node_modules/@pnp/core": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/@pnp/core/-/core-3.21.0.tgz", - "integrity": "sha512-4R+MGo7aitBPUQ4eapLbsiZwPFrMnFZ/6OB4lvXQrtl2IAdZC922gR+bB05O00iEplOcUW9EZJlitLfzTdNuTg==", + "version": "4.0.0-alpha0-v4nightly.20231227", + "resolved": "https://registry.npmjs.org/@pnp/core/-/core-4.0.0-alpha0-v4nightly.20231227.tgz", + "integrity": "sha512-k3oS1swDBL582L7F7YISURVe6RB5U8kgC6E8vzVgbFE6mmW5KV1jP7HG6EhDc6yvAeryL0mPKXvz0OlKu51ntQ==", "dependencies": { "tslib": "2.4.1" }, @@ -2749,9 +2749,9 @@ } }, "@pnp/core": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/@pnp/core/-/core-3.21.0.tgz", - "integrity": "sha512-4R+MGo7aitBPUQ4eapLbsiZwPFrMnFZ/6OB4lvXQrtl2IAdZC922gR+bB05O00iEplOcUW9EZJlitLfzTdNuTg==", + "version": "4.0.0-alpha0-v4nightly.20231227", + "resolved": "https://registry.npmjs.org/@pnp/core/-/core-4.0.0-alpha0-v4nightly.20231227.tgz", + "integrity": "sha512-k3oS1swDBL582L7F7YISURVe6RB5U8kgC6E8vzVgbFE6mmW5KV1jP7HG6EhDc6yvAeryL0mPKXvz0OlKu51ntQ==", "requires": { "tslib": "2.4.1" } diff --git a/tools/buildsystem/package.json b/tools/buildsystem/package.json index 273a8d262..d2bded099 100644 --- a/tools/buildsystem/package.json +++ b/tools/buildsystem/package.json @@ -9,7 +9,7 @@ "type": "module", "typings": "./index", "dependencies": { - "@pnp/core": "^3.21.0", + "@pnp/core": "^4.0.0-alpha0-v4nightly.20231227", "globby": "^14.0.0", "liftoff": "^4.0.0", "webpack": "^5.89.0", diff --git a/tools/buildsystem/src/behaviors/replace-version.ts b/tools/buildsystem/src/behaviors/replace-version.ts index c483de01f..c530c89ad 100644 --- a/tools/buildsystem/src/behaviors/replace-version.ts +++ b/tools/buildsystem/src/behaviors/replace-version.ts @@ -4,7 +4,17 @@ import { readFile } from "fs/promises"; import buildWriteFile from "../lib/write-file.js"; import { resolve } from "path"; -export function ReplaceVersion(paths: string[], versionMask = /\$\$Version\$\$/img): TimelinePipe { +export interface IReplaceVersionOptions { + versionMask?: string | RegExp; + pathsResolved?: boolean; +} + +export function ReplaceVersion(paths: string[], options: IReplaceVersionOptions): TimelinePipe { + + options = { + versionMask: /\$\$Version\$\$/img, + ...options, + } return (instance: BuildTimeline) => { @@ -16,10 +26,10 @@ export function ReplaceVersion(paths: string[], versionMask = /\$\$Version\$\$/i paths.forEach(async (path) => { - const resolvedPath = resolve(target.resolvedOutDir, path); + const resolvedPath = options?.pathsResolved ? path : resolve(target.resolvedOutDir, path); this.log(`Resolving path '${path}' to '${resolvedPath}'.`, 0); const file = await readFile(resolve(resolvedPath)); - await buildWriteFile(resolvedPath, file.toString().replace(versionMask, version)); + await buildWriteFile(resolvedPath, file.toString().replace(options.versionMask, version)); }); }); diff --git a/tools/local-module-resolver/esm.ts b/tools/local-module-resolver/esm.ts index 2c60f7e49..6398cef4a 100644 --- a/tools/local-module-resolver/esm.ts +++ b/tools/local-module-resolver/esm.ts @@ -18,7 +18,7 @@ export function createResolve(innerPath: string): ResolverFunc { return async function (specifier: string, context: ResolveContext, defaultResolve: ResolverFunc): Promise { - if (specifier.startsWith("@pnp")) { + if (specifier.startsWith("@pnp") && specifier !== "@pnp/buildsystem") { const modulePath = specifier.substring(4);