Skip to content

Commit 1486c92

Browse files
authored
feat: add emitOriginalFileName option (#187)
1 parent 00721ef commit 1486c92

File tree

14 files changed

+322
-228
lines changed

14 files changed

+322
-228
lines changed

.changeset/cold-suits-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rollup-extras/plugin-copy": minor
3+
---
4+
5+
added emitOriginalFileName option, default to 'absolute' as it is required by rollup documentation, allows to be set to 'relative' or a function to customize the name

plugin-angularjs-template-cache/tests/index.spec.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,51 +60,51 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
6060
await (pluginInstance as any).buildStart.apply(rollupContextMock);
6161
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
6262
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
63-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
64-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
65-
expect(glob).toBeCalledWith('./**/*.html');
63+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
64+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
65+
expect(glob).toHaveBeenCalledWith('./**/*.html');
6666
});
6767

6868
it('custom - string', async () => {
6969
const pluginInstance = plugin('./views/**/*.html');
7070
await (pluginInstance as any).buildStart.apply(rollupContextMock);
7171
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
7272
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
73-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
74-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
75-
expect(glob).toBeCalledWith('./views/**/*.html');
73+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
74+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
75+
expect(glob).toHaveBeenCalledWith('./views/**/*.html');
7676
});
7777

7878
it('custom - array', async () => {
7979
const pluginInstance = plugin(['./views/**/*.html', './**/*.html']);
8080
await (pluginInstance as any).buildStart.apply(rollupContextMock);
8181
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
8282
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
83-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
84-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
85-
expect(glob).toBeCalledWith('./views/**/*.html');
86-
expect(glob).toBeCalledWith('./**/*.html');
83+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
84+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
85+
expect(glob).toHaveBeenCalledWith('./views/**/*.html');
86+
expect(glob).toHaveBeenCalledWith('./**/*.html');
8787
});
8888

8989
it('custom templates property - string', async () => {
9090
const pluginInstance = plugin({templates: './views/**/*.html'});
9191
await (pluginInstance as any).buildStart.apply(rollupContextMock);
9292
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
9393
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
94-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
95-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
96-
expect(glob).toBeCalledWith('./views/**/*.html');
94+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
95+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
96+
expect(glob).toHaveBeenCalledWith('./views/**/*.html');
9797
});
9898

9999
it('custom templates property - array', async () => {
100100
const pluginInstance = plugin({templates: ['./views/**/*.html', './**/*.html']});
101101
await (pluginInstance as any).buildStart.apply(rollupContextMock);
102102
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
103103
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
104-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
105-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
106-
expect(glob).toBeCalledWith('./views/**/*.html');
107-
expect(glob).toBeCalledWith('./**/*.html');
104+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
105+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
106+
expect(glob).toHaveBeenCalledWith('./views/**/*.html');
107+
expect(glob).toHaveBeenCalledWith('./**/*.html');
108108
});
109109

110110
it('!isFile', async () => {
@@ -145,8 +145,8 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
145145
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
146146
const result = await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
147147
expect(result.includes('$templateCache.put("id", "<html></html>");')).toBe(true);
148-
expect(transformTemplateUri).toBeCalledWith('aFolder/test.html');
149-
expect(transformTemplateUri).toBeCalledWith('aFolder/test2.html');
148+
expect(transformTemplateUri).toHaveBeenCalledWith('aFolder/test.html');
149+
expect(transformTemplateUri).toHaveBeenCalledWith('aFolder/test2.html');
150150
});
151151
});
152152

@@ -158,7 +158,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
158158
const result = await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
159159
expect(result.includes('$templateCache.put("aFolder/test.html", "some text");')).toBe(true);
160160
expect(result.includes('$templateCache.put("aFolder/test2.html", "some text");')).toBe(true);
161-
expect(processHtml).toBeCalledWith('<html></html>');
161+
expect(processHtml).toHaveBeenCalledWith('<html></html>');
162162
expect(processHtml).toBeCalledTimes(2);
163163
});
164164

@@ -212,17 +212,17 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
212212
await (pluginInstance as any).buildStart.call(rollupContextMock);
213213
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
214214
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
215-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test.html');
216-
expect(rollupContextMock.addWatchFile).toBeCalledWith('aFolder/test2.html');
215+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test.html');
216+
expect(rollupContextMock.addWatchFile).toHaveBeenCalledWith('aFolder/test2.html');
217217
});
218218

219219
it('off', async () => {
220220
const pluginInstance = plugin({watch: false});
221221
await (pluginInstance as any).buildStart.call(rollupContextMock);
222222
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
223223
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
224-
expect(rollupContextMock.addWatchFile).not.toBeCalledWith('aFolder/test.html');
225-
expect(rollupContextMock.addWatchFile).not.toBeCalledWith('aFolder/test2.html');
224+
expect(rollupContextMock.addWatchFile).not.toHaveBeenCalledWith('aFolder/test.html');
225+
expect(rollupContextMock.addWatchFile).not.toHaveBeenCalledWith('aFolder/test2.html');
226226
});
227227
});
228228

@@ -234,7 +234,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
234234
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
235235
expect(createLogger).lastCalledWith('@rollup-extras/plugin-angularjs-template-cache');
236236
expect(loggerStart).lastCalledWith('inlining templates', LogLevel.verbose);
237-
expect(loggerFinish).toBeCalledWith('inlined aFolder/test.html, aFolder/test2.html');
237+
expect(loggerFinish).toHaveBeenCalledWith('inlined aFolder/test.html, aFolder/test2.html');
238238
});
239239

240240
it('more than 5 templates', async () => {
@@ -246,7 +246,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
246246
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
247247
expect(createLogger).lastCalledWith('@rollup-extras/plugin-angularjs-template-cache');
248248
expect(loggerStart).lastCalledWith('inlining templates', LogLevel.verbose);
249-
expect(loggerFinish).toBeCalledWith('inlined 6 templates');
249+
expect(loggerFinish).toHaveBeenCalledWith('inlined 6 templates');
250250
});
251251

252252
it('true', async () => {
@@ -262,8 +262,8 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
262262
await (pluginInstance as any).buildStart.call(rollupContextMock);
263263
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
264264
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
265-
expect(logger).toBeCalledWith('\taFolder/test.html → aFolder/test.html', LogLevel.info);
266-
expect(logger).toBeCalledWith('\taFolder/test2.html → aFolder/test2.html', LogLevel.info);
265+
expect(logger).toHaveBeenCalledWith('\taFolder/test.html → aFolder/test.html', LogLevel.info);
266+
expect(logger).toHaveBeenCalledWith('\taFolder/test2.html → aFolder/test2.html', LogLevel.info);
267267
});
268268

269269
it('exception', async () => {
@@ -273,7 +273,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
273273
await (pluginInstance as any).buildStart.call(rollupContextMock);
274274
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
275275
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
276-
expect(logger).toBeCalledWith('error reading file aFolder/test.html', LogLevel.warn, expect.objectContaining({ stack: '' }));
276+
expect(logger).toHaveBeenCalledWith('error reading file aFolder/test.html', LogLevel.warn, expect.objectContaining({ stack: '' }));
277277
});
278278

279279
it('missing directory exception', async () => {
@@ -283,7 +283,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
283283
await (pluginInstance as any).buildStart.call(rollupContextMock);
284284
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
285285
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
286-
expect(logger).toBeCalledWith('error reading file aFolder/test.html', undefined, expect.objectContaining({ code: 'ENOENT', stack: '' }));
286+
expect(logger).toHaveBeenCalledWith('error reading file aFolder/test.html', undefined, expect.objectContaining({ code: 'ENOENT', stack: '' }));
287287
});
288288
});
289289

@@ -299,7 +299,7 @@ describe('@rollup-extras/plugin-angularjs-template-cache', () => {
299299
it('autoImport - emits entry point', async () => {
300300
const pluginInstance = plugin({autoImport: true});
301301
await (pluginInstance as any).buildStart.call(rollupContextMock);
302-
expect(rollupContextMock.emitFile).toBeCalledWith({id: '\0templates:templates', type: 'chunk'});
302+
expect(rollupContextMock.emitFile).toHaveBeenCalledWith({id: '\0templates:templates', type: 'chunk'});
303303
await (pluginInstance as any).resolveId.call(rollupContextMock, 'templates');
304304
await (pluginInstance as any).load.call(rollupContextMock, '\0templates:templates');
305305
});

plugin-binify/tests/index.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe('@rollup-extras/plugin-binify', () => {
5757
}
5858
});
5959
expect(fs.chmod).toBeCalledTimes(1);
60-
expect(fs.chmod).toBeCalledWith('/dist2/index.js', 0o755);
60+
expect(fs.chmod).toHaveBeenCalledWith('/dist2/index.js', 0o755);
6161
expect(loggerStart).toHaveBeenCalledTimes(1);
62-
expect(loggerStart).toBeCalledWith(expect.any(String), LogLevel.verbose);
62+
expect(loggerStart).toHaveBeenCalledWith(expect.any(String), LogLevel.verbose);
6363
expect(loggerFinish).toHaveBeenCalledTimes(1);
6464
expect(loggerUpdate).toHaveBeenCalledTimes(2);
6565
expect(chunk.map.mappings).toEqual(';;');
@@ -89,7 +89,7 @@ describe('@rollup-extras/plugin-binify', () => {
8989
});
9090
expect(fs.chmod).toBeCalledTimes(0);
9191
expect(loggerStart).toHaveBeenCalledTimes(1);
92-
expect(loggerStart).toBeCalledWith(expect.any(String), LogLevel.verbose);
92+
expect(loggerStart).toHaveBeenCalledWith(expect.any(String), LogLevel.verbose);
9393
expect(loggerFinish).toHaveBeenCalledTimes(1);
9494
expect(chunk.map.mappings).toEqual(';;');
9595
expect(chunk.code).toEqual('#!/usr/bin/env node\nconst test = 1;');
@@ -121,7 +121,7 @@ describe('@rollup-extras/plugin-binify', () => {
121121
});
122122
expect(fs.chmod).toBeCalledTimes(0);
123123
expect(loggerStart).toHaveBeenCalledTimes(1);
124-
expect(loggerStart).toBeCalledWith(expect.any(String), LogLevel.verbose);
124+
expect(loggerStart).toHaveBeenCalledWith(expect.any(String), LogLevel.verbose);
125125
expect(loggerFinish).toHaveBeenCalledTimes(1);
126126
expect(chunk.map.mappings).toEqual(';;');
127127
expect(chunk.code).toEqual('#!/usr/bin/env node\nconst test = 1;');
@@ -151,7 +151,7 @@ describe('@rollup-extras/plugin-binify', () => {
151151
'test.js': { ...chunk, isEntry: false, fileName: 'test.js' }
152152
});
153153
expect(fs.chmod).toBeCalledTimes(1);
154-
expect(fs.chmod).toBeCalledWith('/dist2/index.js', 0o755);
154+
expect(fs.chmod).toHaveBeenCalledWith('/dist2/index.js', 0o755);
155155
});
156156

157157
it('filters out assets by default', async () => {
@@ -178,7 +178,7 @@ describe('@rollup-extras/plugin-binify', () => {
178178
'test.js': { ...chunk, type: 'asset', fileName: 'test.js' }
179179
});
180180
expect(fs.chmod).toBeCalledTimes(1);
181-
expect(fs.chmod).toBeCalledWith('/dist2/index.js', 0o755);
181+
expect(fs.chmod).toHaveBeenCalledWith('/dist2/index.js', 0o755);
182182
});
183183

184184
it('filter can be applied', async () => {
@@ -210,7 +210,7 @@ describe('@rollup-extras/plugin-binify', () => {
210210
it('verbose: true raises loglevel to info', async () => {
211211
const pluginInstance = plugin({ verbose: true });
212212
await (pluginInstance as any).renderStart({ dir: '/dist2' });
213-
expect(loggerStart).toBeCalledWith(expect.any(String), LogLevel.info);
213+
expect(loggerStart).toHaveBeenCalledWith(expect.any(String), LogLevel.info);
214214
});
215215

216216
it('no dir in output options', async () => {
@@ -223,13 +223,13 @@ describe('@rollup-extras/plugin-binify', () => {
223223
fileName: 'index.js'
224224
}
225225
});
226-
expect(fs.chmod).toBeCalledWith('index.js', 0o755);
226+
expect(fs.chmod).toHaveBeenCalledWith('index.js', 0o755);
227227
});
228228

229229
it('different plugin name (for debug)', async () => {
230230
const pluginInstance = plugin({ pluginName: 'test' });
231231
await (pluginInstance as any).renderStart({});
232-
expect(createLogger).toBeCalledWith('test');
232+
expect(createLogger).toHaveBeenCalledWith('test');
233233
});
234234

235235
it('shebang can be changed', async () => {
@@ -303,7 +303,7 @@ describe('@rollup-extras/plugin-binify', () => {
303303
fileName: 'index.js'
304304
}
305305
});
306-
expect(fs.chmod).toBeCalledWith('/dist2/index.js', 0);
306+
expect(fs.chmod).toHaveBeenCalledWith('/dist2/index.js', 0);
307307
});
308308

309309
it('logs error on fs error', async () => {
@@ -332,6 +332,6 @@ describe('@rollup-extras/plugin-binify', () => {
332332
fileName: 'index.js'
333333
}
334334
});
335-
expect(log).toBeCalledWith(expect.any(String), LogLevel.error, error);
335+
expect(log).toHaveBeenCalledWith(expect.any(String), LogLevel.error, error);
336336
});
337337
});

0 commit comments

Comments
 (0)