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

fix(node): unable to run projen package on windows #2761

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 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
1 change: 0 additions & 1 deletion .gitattributes

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

13 changes: 10 additions & 3 deletions .github/workflows/build.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/release.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-main.yml

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

1 change: 0 additions & 1 deletion .gitignore

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

2 changes: 1 addition & 1 deletion .gitpod.yml

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

2 changes: 1 addition & 1 deletion .npmignore

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

1 change: 0 additions & 1 deletion .projen/files.json

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

19 changes: 11 additions & 8 deletions .projen/tasks.json

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

41 changes: 12 additions & 29 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const project = new cdk.JsiiProject({
gitpod: true,
devContainer: true,
// since this is projen, we need to always compile before we run
projenCommand: "/bin/bash ./projen.bash",
projenCommand: "node ./projen.bootstrap.js",

// cli tests need projen to be compiled
compileBeforeTest: true,
Expand Down Expand Up @@ -122,23 +122,17 @@ const project = new cdk.JsiiProject({
autoApproveOptions: { allowedUsernames: ["cdklabs-automation"] },

docgenFilePath: "docs/api/API.md",
});

// this script is what we use as the projen command in this project
// it will compile the project if needed and then run the cli.
new TextFile(project, "projen.bash", {
lines: [
"#!/bin/bash",
`# ${PROJEN_MARKER}`,
"set -euo pipefail",
"if [ ! -f lib/cli/index.js ]; then",
' echo "bootstrapping..."',
" npx jsii --silence-warnings=reserved-word --no-fix-peer-dependencies",
"fi",
"exec bin/projen $@",
],
workflowWindows: true,
workflowMacOS: true,
});
project.npmignore.exclude("/projen.bash");

project.jest.config.haste = {
...(project.jest.config.haste ?? {}),
forceNodeFilesystemAPI: true,
};

project.npmignore.exclude("/projen.bootstrap.js");

project.addExcludeFromCleanup("test/**"); // because snapshots include the projen marker...
project.gitignore.include("templates/**");
Expand Down Expand Up @@ -185,7 +179,7 @@ project.github.mergify.addRule({
project.gitpod.addCustomTask({
name: "Setup",
init: "yarn install",
prebuild: "bash ./projen.bash",
prebuild: "node ./projen.bootstrap.js",
command: "npx projen build",
});

Expand Down Expand Up @@ -234,18 +228,7 @@ function setupBundleTaskRunner() {
description: 'Bundle the run-task script needed for "projen eject"',
exec: `esbuild src/task-runtime.ts --outfile=${taskRunnerPath} --bundle --platform=node --external:"*/package.json"`,
});
task.exec(
`echo "#!/usr/bin/env node" | cat - lib/run-task.js | tee lib/run-task.js > /dev/null`,
{
name: "Insert Node shebang to beginning of the file",
}
);
task.exec(
`echo "const runtime = new TaskRuntime(\\".\\");\nruntime.runTask(process.argv[2]);" >> ${taskRunnerPath}`,
{
name: "Add driver code to end of the file",
}
);
task.exec("node bundle.task-runner.js");
project.postCompileTask.spawn(task);
}

Expand Down
6 changes: 6 additions & 0 deletions bundle.task-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fs = require('fs')
const path = require('path')

const runTaskPath = path.join(__dirname, 'lib', 'run-task.js');
const runTask = fs.readFileSync(runTaskPath, { encoding: 'utf-8'});
fs.writeFileSync(runTaskPath, `#!/usr/bin/env node\n${runTask}\nconst runtime = new TaskRuntime(".");\nruntime.runTask(process.argv[2]);`)
Loading
Loading