Skip to content

Commit 751e407

Browse files
committed
Ensure newline after registry string in authutil
Add a newline at the end of the registry string in authutil, to ensure that it's a proper POSIX file.
1 parent 53b8394 commit 751e407

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

__tests__/authutil.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('authutil tests', () => {
123123
await auth.configAuthentication('https://registry.npmjs.org/');
124124
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
125125
expect(contents).toBe(
126-
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
126+
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
127127
);
128128
});
129129

@@ -132,7 +132,7 @@ describe('authutil tests', () => {
132132
await auth.configAuthentication('https://registry.npmjs.org/');
133133
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
134134
expect(contents).toBe(
135-
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
135+
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
136136
);
137137
});
138138

@@ -141,7 +141,7 @@ describe('authutil tests', () => {
141141
await auth.configAuthentication('https://registry.npmjs.org/');
142142
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
143143
expect(contents).toBe(
144-
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
144+
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
145145
);
146146
});
147147

@@ -151,7 +151,7 @@ describe('authutil tests', () => {
151151
await auth.configAuthentication('https://registry.npmjs.org/');
152152
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
153153
expect(contents).toBe(
154-
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
154+
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
155155
);
156156
});
157157

@@ -161,7 +161,7 @@ describe('authutil tests', () => {
161161
await auth.configAuthentication('https://registry.npmjs.org/');
162162
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
163163
expect(contents).toBe(
164-
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
164+
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
165165
);
166166
});
167167

@@ -171,7 +171,7 @@ describe('authutil tests', () => {
171171
await auth.configAuthentication('https://registry.npmjs.org/');
172172
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
173173
expect(contents).toBe(
174-
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
174+
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
175175
);
176176
});
177177

@@ -184,7 +184,7 @@ describe('authutil tests', () => {
184184
await auth.configAuthentication('https://registry.npmjs.org/');
185185
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
186186
expect(contents).toBe(
187-
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
187+
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
188188
);
189189
});
190190

@@ -194,7 +194,7 @@ describe('authutil tests', () => {
194194
await auth.configAuthentication('https://registry.npmjs.org/');
195195
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
196196
expect(contents).toBe(
197-
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
197+
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
198198
);
199199
});
200200
});

src/authutil.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
4444
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
4545
const registryString = `${scope}registry=${registryUrl}`;
4646
newContents += `${authString}${os.EOL}${registryString}`;
47+
if (newContents && !newContents.endsWith(os.EOL)) {
48+
newContents += os.EOL;
49+
}
4750
fs.writeFileSync(fileLocation, newContents);
4851
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
4952
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it

0 commit comments

Comments
 (0)