Skip to content

Commit 15f748d

Browse files
authored
fix(pacmak): Find the tarball location on windows even if prepack is run (#4795)
I believe this fixes [the issue where windows runners with prepack scripts fail](#4793). The fix is a little clumsy - it might be better to pull the line manipulation out to a function. ~Raising for discussion, as testing this is a bit fiddly. I'll report back once tested.~ Update: I can confirm this fixes the reported issue. Tested by running a successful `jsii-pacmak` build of my repo with `prepack` scripts in macos, ubuntu and windows github runners. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent 86a253b commit 15f748d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/jsii-pacmak/lib/packaging.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from 'fs-extra';
22
import type { Assembly, TypeSystem } from 'jsii-reflect';
3-
import * as os from 'os';
43
import * as path from 'path';
54

65
import { Scratch, shell } from './util';
@@ -79,14 +78,17 @@ export class JsiiModule {
7978
// Take only the last line of npm pack which should contain the
8079
// tarball name. otherwise, there can be a lot of extra noise there
8180
// from scripts that emit to STDOUT.
82-
const lines = out.trim().split(os.EOL);
81+
// Since we are interested in the text *after* the last newline, splitting on '\n' is correct
82+
// both on Linux/Mac (EOL = '\n') and Windows (EOL = '\r\n'), and also for UNIX tools running
83+
// on Windows (expected EOL = '\r\n', actual EOL = '\n').
84+
const lines = out.trim().split('\n');
8385
const lastLine = lines[lines.length - 1].trim();
8486

8587
if (!lastLine.endsWith('.tgz') && !lastLine.endsWith('.tar.gz')) {
8688
throw new Error(
8789
`${packCommand} did not produce tarball from ${
8890
this.moduleDirectory
89-
} into ${tmpdir} (output was ${JSON.stringify(lines)})`,
91+
} into ${tmpdir} (output was ${JSON.stringify(lines.map((l) => l.trimEnd()))})`,
9092
);
9193
}
9294

0 commit comments

Comments
 (0)