Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildsystem cjs #2877

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 25 additions & 8 deletions buildsystem-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,36 @@ Logger.subscribe(ConsoleListener("", {

const logLevel = LogLevel.Verbose;
const distFolder = "./dist/packages";
const commonPublishTags = ["--access", "public", "--provenance"];
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.

4 changes: 2 additions & 2 deletions tools/buildsystem/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pnp/buildsystem",
"version": "4.0.0-beta5",
"version": "4.0.0-beta6",
"bin": {
"pnpbuild": "bin/buildsystem.js"
},
Expand All @@ -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
Loading