-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(lambda-nodejs): copy .npmrc for pnpm to enable private registry authentication #36587
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
a651725
f26205e
f9ae54e
9eba1b9
b66e05c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @myorg:registry=https://registry.example.com/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -605,6 +605,71 @@ test('Detects pnpm-lock.yaml', () => { | |
| }); | ||
| }); | ||
|
|
||
| test('pnpm with nodeModules writes .npmrc using base64 for private registry authentication', () => { | ||
| const pnpmLock = '/project/pnpm-lock.yaml'; | ||
| const npmrcFixture = path.join(__dirname, '.testnpmrc'); | ||
| const npmrcBase64 = Buffer.from(fs.readFileSync(npmrcFixture, 'utf-8')).toString('base64'); | ||
|
|
||
| const originalFindUp = util.findUp; | ||
| jest.spyOn(util, 'findUp').mockImplementation((name, dir) => | ||
| name === '.npmrc' ? npmrcFixture : originalFindUp(name, dir), | ||
| ); | ||
|
|
||
| Bundling.bundle(stack, { | ||
| entry: __filename, | ||
| projectRoot, | ||
| depsLockFilePath: pnpmLock, | ||
| runtime: STANDARD_RUNTIME, | ||
| architecture: Architecture.X86_64, | ||
| nodeModules: ['delay'], | ||
| forceDockerBundling: true, | ||
| }); | ||
|
|
||
| expect(Code.fromAsset).toHaveBeenCalledWith(path.dirname(pnpmLock), { | ||
| assetHashType: AssetHashType.OUTPUT, | ||
| bundling: expect.objectContaining({ | ||
| command: expect.arrayContaining([ | ||
| expect.stringContaining(`echo '${npmrcBase64}' | base64 -d`), | ||
| ]), | ||
| }), | ||
| }); | ||
| }); | ||
|
|
||
| test('pnpm with nodeModules writes .npmrc using base64 for private registry authentication on win32', () => { | ||
| const osPlatformMock = jest.spyOn(os, 'platform').mockReturnValue('win32'); | ||
| const pnpmLock = 'C:\\project\\pnpm-lock.yaml'; | ||
| const npmrcFixture = path.join(__dirname, '.testnpmrc'); | ||
| const npmrcBase64 = Buffer.from(fs.readFileSync(npmrcFixture, 'utf-8')).toString('base64'); | ||
|
|
||
| const originalFindUp = util.findUp; | ||
| jest.spyOn(util, 'findUp').mockImplementation((name, dir) => | ||
| name === '.npmrc' ? npmrcFixture : originalFindUp(name, dir), | ||
| ); | ||
| jest.spyOn(path, 'basename').mockReturnValueOnce('pnpm-lock.yaml'); | ||
| jest.spyOn(path, 'relative').mockReturnValueOnce('test\\bundling.test.ts').mockReturnValueOnce('pnpm-lock.yaml'); | ||
|
|
||
| Bundling.bundle(stack, { | ||
| entry: __filename, | ||
| projectRoot: 'C:\\project', | ||
| depsLockFilePath: pnpmLock, | ||
| runtime: STANDARD_RUNTIME, | ||
| architecture: Architecture.X86_64, | ||
| nodeModules: ['delay'], | ||
| forceDockerBundling: true, | ||
| }); | ||
|
|
||
| expect(Code.fromAsset).toHaveBeenCalledWith(expect.any(String), { | ||
| assetHashType: AssetHashType.OUTPUT, | ||
| bundling: expect.objectContaining({ | ||
| command: expect.arrayContaining([ | ||
| expect.stringContaining(`echo '${npmrcBase64}' | base64 -d`), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird. I'd expect this to be Bundling.bundle(stack, { platform: 'win32', ... });Instead of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's completely my fault for rushing this and trying to copy the test from 158. I'll try and fix this today. Thanks for catching it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. So digging into this, the The reason I missed the |
||
| ]), | ||
| }), | ||
| }); | ||
|
|
||
| osPlatformMock.mockRestore(); | ||
| }); | ||
|
|
||
| test('Detects bun.lockb', () => { | ||
| const bunLock = path.join(__dirname, '..', 'bun.lockb'); | ||
| Bundling.bundle(stack, { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Can you please add coverage for the
win32platform?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added and re-based.