Skip to content

Commit

Permalink
Merge pull request #2877 from patrick-rodgers/version-4
Browse files Browse the repository at this point in the history
buildsystem cjs
  • Loading branch information
patrick-rodgers authored Dec 27, 2023
2 parents 6f7d9c5 + 7cf357c commit 9e950c3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"program": "${workspaceRoot}/tools/buildsystem/bin/buildsystem.ts",
"args": [
"-n",
"build"
"package"
],
"cwd": "${workspaceRoot}",
"preLaunchTask": "build-buildsystem",
Expand Down
31 changes: 24 additions & 7 deletions buildsystem-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -90,7 +107,7 @@ const commonBehaviors = [
PnPLogging(logLevel),
]

export default [<BuildSchema>{
export default <BuildSchema[]>[{
name: "build",
distFolder,
targets: [
Expand All @@ -112,23 +129,23 @@ export default [<BuildSchema>{
targets: [
resolve("./packages/tsconfig.json"),
],
behaviors: [PnPBuild(), PnPPackage(), ...commonBehaviors],
behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), ...commonBehaviors],
},
{
name: "publish",
distFolder,
targets: [
resolve("./packages/tsconfig.json"),
],
behaviors: [PnPBuild(), PnPPackage(), PnPPublish(commonPublishTags), ...commonBehaviors],
behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), PnPPublish(commonPublishTags), ...commonBehaviors],
},
{
name: "publish-beta",
distFolder,
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",
Expand All @@ -144,5 +161,5 @@ export default [<BuildSchema>{
targets: [
resolve("./packages/tsconfig.json"),
],
behaviors: [PnPBuild(), PnPPackage(), PublishNightly([...commonPublishTags], "v4nightly"), ...commonBehaviors],
behaviors: [PnPBuild(), PnPBuildCommonJS(), PnPPackage(), PublishNightly([...commonPublishTags], "v4nightly"), ...commonBehaviors],
}];
2 changes: 1 addition & 1 deletion tools/buildsystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
18 changes: 9 additions & 9 deletions tools/buildsystem/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/buildsystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 13 additions & 3 deletions tools/buildsystem/src/behaviors/replace-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand All @@ -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));
});
});

Expand Down
2 changes: 1 addition & 1 deletion tools/local-module-resolver/esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createResolve(innerPath: string): ResolverFunc {

return async function (specifier: string, context: ResolveContext, defaultResolve: ResolverFunc): Promise<ResolvedValue> {

if (specifier.startsWith("@pnp")) {
if (specifier.startsWith("@pnp") && specifier !== "@pnp/buildsystem") {

const modulePath = specifier.substring(4);

Expand Down

0 comments on commit 9e950c3

Please sign in to comment.