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

Don't normalize file patterns #131

Merged
merged 42 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2c98b75
Rough draft of adding individual interfaces
MilapNaik Nov 8, 2023
c439411
Merge branch 'v4' into create-specific-interfaces
MilapNaik Nov 8, 2023
30c03a6
variable name changes for different options
MilapNaik Nov 13, 2023
824ecb1
Make all changes except a few that are questionable
MilapNaik Nov 17, 2023
518b134
Take out warning since rootDir defaults
MilapNaik Nov 17, 2023
2b07c3a
Merge branch 'master' into create-specific-interfaces
MilapNaik Nov 17, 2023
49a8aff
Make variable optional
MilapNaik Nov 17, 2023
caa31d3
Make rootDir mandatory, fixes 8 failing tests
MilapNaik Nov 17, 2023
3b43372
make stagingDir mandatory for zip package, fixes 1 test
MilapNaik Nov 17, 2023
1b4ed6d
forgot 2 lines from last commit message
MilapNaik Nov 17, 2023
40f5951
Fix 1 more test
MilapNaik Nov 17, 2023
99f7d07
Merge branch 'v4' into create-specific-interfaces
MilapNaik Nov 17, 2023
9a9ea91
Make outfile mandatory in publishOptions, fixes 12 tests
MilapNaik Nov 17, 2023
59cf002
fix 1 more test over copying mistake
MilapNaik Nov 17, 2023
a41bd94
added stagingDir to prepublishToStaging tests to get 10 more tests to…
MilapNaik Nov 17, 2023
1526d68
Changed a few more interfaces that I had forgotten
MilapNaik Nov 17, 2023
5da202d
Attempt to debug github tests
MilapNaik Nov 17, 2023
58dfebe
Test was fixed on github
MilapNaik Nov 17, 2023
fb84132
Fix missing coverage
TwitchBronBron Nov 27, 2023
560da75
delete retainStagingFolder
MilapNaik Nov 27, 2023
b15467a
Remove changing back slashes to forward slashes
MilapNaik Nov 29, 2023
2c921dd
Merge branch 'master' into create-specific-interfaces
MilapNaik Nov 29, 2023
0c3da4a
Merge remote-tracking branch 'origin/create-specific-interfaces' into…
MilapNaik Nov 29, 2023
9b9f3cb
Merge remote-tracking branch 'origin/remove-retainStagingFolder' into…
MilapNaik Nov 29, 2023
6b5ef31
Merge branch 'v4' into create-specific-interfaces
MilapNaik Nov 29, 2023
2e31ad4
Merge branch 'create-specific-interfaces' into remove-retainStagingFo…
MilapNaik Nov 29, 2023
d005a53
Merge branch 'remove-retainStagingFolder' into TBD-160-dont-normalize…
MilapNaik Nov 29, 2023
8a80323
Merge branch 'v4' of https://github.com/rokucommunity/roku-deploy int…
TwitchBronBron Dec 1, 2023
e390716
Merge branch 'remove-retainStagingFolder' into TBD-160-dont-normalize…
TwitchBronBron Dec 1, 2023
eeabd68
put standardizePath() back
MilapNaik Dec 4, 2023
b89128b
Put back more code
MilapNaik Dec 4, 2023
f408c8a
Delete toFrowardSlashes test
MilapNaik Dec 4, 2023
2160545
No longer force all paths to unix style
MilapNaik Dec 4, 2023
8673e63
Fix windows issues
TwitchBronBron Dec 4, 2023
95d9905
fix coverage failure
TwitchBronBron Dec 4, 2023
eec47ad
Merge branch 'v4' into TBD-160-dont-normalize-file-patterns
MilapNaik Dec 12, 2023
787ea0e
Edit readme
MilapNaik Dec 13, 2023
22957ca
Add tests to check for escaped and unescaped glob patterns
MilapNaik Dec 14, 2023
b11be36
Update README.md
MilapNaik Dec 14, 2023
bfcedbb
Update README.md
MilapNaik Dec 14, 2023
565c096
change tests to accomodate windows machines
MilapNaik Dec 14, 2023
0e78524
Process slashes properly
MilapNaik Dec 14, 2023
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ The object structure is as follows:
}
```
#### { src; dest } Object Rules
- if `src` is a non-glob path to a single file, then `dest` should include the filename and extension. For example:
`{ src: "lib/Promise/promise.brs", dest: "source/promise.brs"}`
- if `src` is a non-glob path to a single file, then `dest` should include the filename and extension. For example:

- if `src` is a glob pattern, then `dest` should be a path to the folder in the output directory. For example:
`{ src: "lib/*.brs", dest: "source/lib"}`
Expand Down Expand Up @@ -326,7 +325,7 @@ Here are the available options. The defaults are shown to the right of the optio
"manifest"
]
```
An array of file paths, globs, or {src:string;dest:string} objects that will be copied into the deployment package.
An array of file paths, globs, or `{ src: string; dest: string }` objects that will be copied into the deployment package. Make sure to _exclusively_ use forward slashes ( `/` ) for path separators (even on Windows), as backslashes are reserved for character escaping. You can learn more about this requirement [here](https://www.npmjs.com/package/fast-glob?activeTab=readme#how-to-write-patterns-on-windows).

Using the {src;dest} objects will allow you to move files into different destination paths in the
deployment package. This would be useful for copying environment-specific configs into a common config location
Expand Down
55 changes: 40 additions & 15 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as glob from 'glob';
import type { BeforeZipCallbackInfo } from './RokuDeploy';
import { RokuDeploy } from './RokuDeploy';
import * as errors from './Errors';
import { util, standardizePath as s } from './util';
import { util, standardizePath as s, standardizePathPosix as sp } from './util';
import type { FileEntry, RokuDeployOptions } from './RokuDeployOptions';
import { cwd, expectPathExists, expectPathNotExists, expectThrowsAsync, outDir, rootDir, stagingDir, tempDir, writeFiles } from './testUtils.spec';
import { createSandbox } from 'sinon';
Expand Down Expand Up @@ -1722,7 +1722,7 @@ describe('index', () => {
await rokuDeploy.prepublishToStaging({
files: [
{
src: `${rootDir}/manifest`,
src: sp`${rootDir}/manifest`,
dest: ''
},
{
Expand Down Expand Up @@ -2093,7 +2093,7 @@ describe('index', () => {
src: `long/source/path`,
dest: `long/dest/path`
}])).to.eql([{
src: s`long/source/path`,
src: sp`long/source/path`,
dest: s`long/dest/path`
}]);
});
Expand Down Expand Up @@ -2151,7 +2151,7 @@ describe('index', () => {
src: 'manifest',
dest: undefined
}, {
src: s`source/main.brs`,
src: sp`source/main.brs`,
dest: undefined
}]);
});
Expand All @@ -2163,7 +2163,7 @@ describe('index', () => {
dest: 'source/config.brs'
}
])).to.eql([{
src: s`source/config.dev.brs`,
src: sp`source/config.dev.brs`,
dest: s`source/config.brs`
}]);
});
Expand Down Expand Up @@ -2651,7 +2651,7 @@ describe('index', () => {

describe('getFilePaths', () => {
const otherProjectName = 'otherProject';
const otherProjectDir = s`${rootDir}/../${otherProjectName}`;
const otherProjectDir = sp`${rootDir}/../${otherProjectName}`;
//create baseline project structure
beforeEach(() => {
fsExtra.ensureDirSync(`${rootDir}/components/emptyFolder`);
Expand Down Expand Up @@ -2817,6 +2817,31 @@ describe('index', () => {
}]);
});

it('Finds folder using square brackets glob pattern', async () => {
fsExtra.outputFileSync(`${rootDir}/e/file.brs`, '');
expect(await getFilePaths([
'[test]/*'
],
rootDir
)).to.eql([{
src: s`${rootDir}/e/file.brs`,
dest: s`e/file.brs`
}]);
});

it('Finds folder with escaped square brackets glob pattern as name', async () => {
fsExtra.outputFileSync(`${rootDir}/[test]/file.brs`, '');
fsExtra.outputFileSync(`${rootDir}/e/file.brs`, '');
expect(await getFilePaths([
'\\[test\\]/*'
],
rootDir
)).to.eql([{
src: s`${rootDir}/[test]/file.brs`,
dest: s`[test]/file.brs`
}]);
});

it('throws exception when top-level strings reference files not under rootDir', async () => {
writeFiles(otherProjectDir, [
'manifest'
Expand Down Expand Up @@ -3139,15 +3164,15 @@ describe('index', () => {

//dest not specified
expect(await rokuDeploy.getFilePaths([{
src: s`${cwd}/README.md`
src: sp`${cwd}/README.md`
}], options.rootDir)).to.eql([{
src: s`${cwd}/README.md`,
dest: s`README.md`
}]);

//dest specified
expect(await rokuDeploy.getFilePaths([{
src: path.join(cwd, 'README.md'),
src: sp`${cwd}/README.md`,
dest: 'docs/README.md'
}], options.rootDir)).to.eql([{
src: s`${cwd}/README.md`,
Expand All @@ -3157,7 +3182,7 @@ describe('index', () => {
let paths: any[];

paths = await rokuDeploy.getFilePaths([{
src: s`${cwd}/README.md`,
src: sp`${cwd}/README.md`,
dest: s`docs/README.md`
}], outDir);

Expand All @@ -3169,7 +3194,7 @@ describe('index', () => {
//top-level string paths pointing to files outside the root should thrown an exception
await expectThrowsAsync(async () => {
paths = await rokuDeploy.getFilePaths([
s`${cwd}/README.md`
sp`${cwd}/README.md`
], outDir);
});
});
Expand All @@ -3180,7 +3205,7 @@ describe('index', () => {
]);
expect(
await rokuDeploy.getFilePaths([{
src: path.join('..', 'README.md')
src: sp`../README.md`
}], rootDir)
).to.eql([{
src: s`${rootDir}/../README.md`,
Expand All @@ -3189,7 +3214,7 @@ describe('index', () => {

expect(
await rokuDeploy.getFilePaths([{
src: path.join('..', 'README.md'),
src: sp`../README.md`,
dest: 'docs/README.md'
}], rootDir)
).to.eql([{
Expand All @@ -3204,17 +3229,17 @@ describe('index', () => {
]);
await expectThrowsAsync(
rokuDeploy.getFilePaths([
path.join('..', 'README.md')
path.posix.join('..', 'README.md')
], outDir)
);
});

it('supports overriding paths', async () => {
let paths = await rokuDeploy.getFilePaths([{
src: s`${rootDir}/components/component1.brs`,
src: sp`${rootDir}/components/component1.brs`,
dest: 'comp1.brs'
}, {
src: s`${rootDir}/components/screen1/screen1.brs`,
src: sp`${rootDir}/components/screen1/screen1.brs`,
dest: 'comp1.brs'
}], rootDir);
expect(paths).to.be.lengthOf(1);
Expand Down
4 changes: 2 additions & 2 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class RokuDeploy {
//objects with src: string
if (typeof entry.src === 'string') {
result.push({
src: util.standardizePath(entry.src),
src: entry.src,
dest: util.standardizePath(entry.dest)
});

Expand All @@ -86,7 +86,7 @@ export class RokuDeploy {
//create a distinct entry for each item in the src array
for (let srcEntry of entry.src) {
result.push({
src: util.standardizePath(srcEntry),
src: srcEntry,
dest: util.standardizePath(entry.dest)
});
}
Expand Down
14 changes: 8 additions & 6 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ describe('util', () => {
});
});

describe('toForwardSlashes', () => {
it('returns original value for non-strings', () => {
expect(util.toForwardSlashes(undefined)).to.be.undefined;
expect(util.toForwardSlashes(<any>false)).to.be.false;
describe('standardizePathPosix', () => {
it('returns falsey value back unchanged', () => {
expect(util.standardizePathPosix(null)).to.eql(null);
expect(util.standardizePathPosix(undefined)).to.eql(undefined);
expect(util.standardizePathPosix(false as any)).to.eql(false);
expect(util.standardizePathPosix(0 as any)).to.eql(0);
});

it('converts mixed slashes to forward', () => {
expect(util.toForwardSlashes('a\\b/c\\d/e')).to.eql('a/b/c/d/e');
it('always returns forward slashes', () => {
expect(util.standardizePathPosix('C:\\projects/some\\folder')).to.eql('C:/projects/some/folder');
});
});

Expand Down
30 changes: 20 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,21 @@ export class Util {
if (!thePath) {
return thePath;
}
return path.normalize(
thePath.replace(/[\/\\]+/g, path.sep)
);
return path.normalize(thePath).replace(/[\/\\]+/g, path.sep);
}

/**
* Convert all slashes to forward slashes
* Normalize path and replace all directory separators with current OS separators
* @param thePath
*/
public toForwardSlashes(thePath: string) {
if (typeof thePath === 'string') {
return thePath.replace(/[\/\\]+/g, '/');
} else {
public standardizePathPosix(thePath: string) {
if (!thePath) {
return thePath;
}
return path.normalize(thePath).replace(/[\/\\]+/g, '/');
}


/**
* Do a case-insensitive string replacement
* @param subject the string that will have its contents replaced
Expand Down Expand Up @@ -140,8 +139,6 @@ export class Util {
cwd = cwd.replace(/\\/g, '/');

const globResults = patterns.map(async (pattern) => {
//force all windows-style slashes to unix style
pattern = pattern.replace(/\\/g, '/');
//skip negated patterns (we will use them to filter later on)
if (pattern.startsWith('!')) {
return pattern;
Expand Down Expand Up @@ -245,3 +242,16 @@ export function standardizePath(stringParts, ...expressions: any[]) {
result.join('')
);
}

/**
* A tagged template literal function for standardizing the path and making all path separators forward slashes
*/
export function standardizePathPosix(stringParts, ...expressions: any[]) {
let result = [];
for (let i = 0; i < stringParts.length; i++) {
result.push(stringParts[i], expressions[i]);
}
return util.standardizePathPosix(
result.join('')
);
}