Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
inPathWin32.replace(/\\/g,"/");
```

## Binary Test Strategy
```bash
pnpm run test:unit
pnpm run build-bins

mocha --recursive --timeout 10000 --exit tests/unit
mocha --recursive --timeout 10000 --exit tests/cli/wsl/wsl-cli-to-wsl.test.mjs
npx mocha --recursive --timeout 10000 --exit tests/cli/wsl/wsl-cli-to-wsl.test.mjs

lib/bin_build/dist/index-linux ssdf
```

## Next Steps
* Migrate UI to VitePress
* Cleanup and move to src/ and test/ etc.
Expand Down
1 change: 1 addition & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<textarea class="area"
:value="sOutputWin32ToSlash"
/>
<!-- todo cygwin "/cygdrive/c/" to c:/ -->
</div>
</template>
<script>
Expand Down
2 changes: 1 addition & 1 deletion dev/node-fs-utils-dev/SpawnCmd.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
*
* og from nuxt3-win32-posix-path/dev/node-fs-utils-dev
* spawn for executing commands on controller. make it SSH2Pool like?
* future add support for abort / signal
*
Expand Down
28 changes: 28 additions & 0 deletions dev/windows_env_paths/bash-escape-sequence-echo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env fish
# can't end with \' or \"
# echo 'c\'
# echo "c\"
echo c\

# work
echo 'c\hi'
echo "c\hi"
echo "c\\hi"
echo c\\hi

# no work:
echo c\hi


# Home
echo ~
echo ~/repo
## quotes dont work at all with echo at least
echo "~"
echo '~'
echo "~/repo"
echo '~/repo'
echo "$HOME" # works
echo '$HOME'
echo "$HOME/repo" # works
echo '$HOME/repo'
16 changes: 16 additions & 0 deletions dev/windows_env_paths/cli-escape-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Cli Escape Lines
* note. literally node cannot see the front slash without quotes
```bash
node ./cli-node.mjs "c:/Users/Public/Docum ents"
node ./cli-node.mjs "c:/Users/Public/Documents"
node ./cli-node.mjs c:/Users/Public/Documents
node ./cli-node.mjs c:\Users\Public\Documents
```

## One
```bash
node ./cli-node.mjs c:\Users\Public\Documents
node ./cli-node.mjs c:\\Users\\Public\\Documents
node ./cli-node.mjs "c:\Users\Public\Documents"
node ./cli-node.mjs 'c:\Users\Public\Documents'
```
16 changes: 16 additions & 0 deletions dev/windows_env_paths/cli-escape-lines.parsed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c\
'c\hi'
"c\hi"
"c\\hi"
c\\hi
c\hi
~
~/repo
"~"
'~'
"~/repo"
'~/repo'
"$HOME"
'$HOME'
"$HOME/repo"
'$HOME/repo'
139 changes: 139 additions & 0 deletions dev/windows_env_paths/cli-escape-lines.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
yarn add mocha -D

package.json
"imports": {
"##/*": {
"default": "./*"
},
},
"type": "module",

jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"##/*": ["./*"]
}
},
"exclude": ["node_modules", ".nuxt", "dist"]
}



*/
// import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
// const assert = require('assert');
// const {describe,it} = require('mocha');
import assert from 'node:assert';
import { describe, it} from 'mocha';
/*
1.
yarn add mocha @babel/polyfill @babel/register @babel/preset-env babel-plugin-module-resolver --dev
yarn add @babel/core --dev
2.
-r @babel/register -r babel-plugin-module-resolver

3.
.babelrc
{

"presets": ["@babel/preset-env"],
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"test": "./test",
"underscore": "lodash",

"~": "./"
}
}]
]

}
test specific timeout
this.timeout(500);//500ms
*/
/**
* Should put this somewhere safe
* todo filepath needs to be initialized as well...
* @param fileName .json
* @param data will automatically be changed
*/
import fs from 'node:fs';
function writeToFile(fileName,data,space=2){
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
const filePath = `dev/pbs/test/${sFileName}`
fs.writeFileSync(filePath,
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
);
}


/**
* todo move / extract
* @param line {string}
* @returns {string|null}
*/
function handleBashLine(line){
/* this regex checks for empty lines and lines with only comments */
if(/^\s*#$/.test(line)) return null;
const rowWithoutComment = line
.replace(/#.*$/,'')
.trim();
if(rowWithoutComment === '') return null;
return rowWithoutComment;
}
describe('handleBashLine', function(){
it('empty line', function(){
const line = '';
const expected = null;
const result = handleBashLine(line);
assert.strictEqual(result,expected);
});
it("comment line", function(){
const line = '# some comments';
const expected = null;
const result = handleBashLine(line);
assert.strictEqual(result,expected);
});
/* need to double check space infront of hash but leave for now */
it('comment at end of line', function(){
const line = 'echo hi # some comments';
const expected = "echo hi";
const result = handleBashLine(line);
assert.strictEqual(result,expected);
});
});
describe('cli-escape-lines.test.mjs', function(){
let filePath = "dev/windows_env_paths/cli-escape-lines.txt.sh"

/** @type {string} */
let rawData;
/** @type {string[]} */
let data;
before(()=>{
/* load file */
rawData = fs.readFileSync(filePath,'utf8')
.replace(/\r\n/g,'\n');
data = rawData.split('\n')
});
it('Ignore # and empty lines', function(){
//assert.strictEqual(1,1);//require assert
assert.strictEqual(typeof rawData,'string');
/* open write stream */
const ws = fs.createWriteStream('dev/windows_env_paths/cli-escape-lines.parsed.txt');
for (let i = 0; i < data.length; i++) {
const line = data[i];
const row = handleBashLine(line);
if(row === null) continue;
ws.write(row + '\n');
}

ws.end();

});
});
19 changes: 19 additions & 0 deletions dev/windows_env_paths/cli-escape-lines.txt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
c\
'c\hi'
"c\hi"
"c\\hi"
c\\hi
# no work:
c\hi
# Home
~
~/repo
## quotes dont work at all with at least
"~"
'~'
"~/repo"
'~/repo'
"$HOME" # works
'$HOME'
"$HOME/repo" # works
'$HOME/repo'
7 changes: 7 additions & 0 deletions dev/windows_env_paths/cli-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Testing how zsh passes arguments to node
node dev/windows_env_paths/cli-node.mjs "c:/Users/Public/Docum ents"
* @type {string[]}
*/
const args = process.argv.slice(2);
console.log(args,args[0][2],'len: ',args.length);
19 changes: 18 additions & 1 deletion dev_docs/windows_env_paths/readme_windows_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ ls env:
```

# using pkg to export the exe
* for cross platform url util?
* for cross platform url util?


# also program files
```powershell
<#
c:/progra~1/
c:/progra~2/
c:/progra~3/
#3 is program data
$env:PUBLIC
%PUBLIC%
"/cygdrive/c/"

#>
```
* node uses CMD envs...
* note use process.env
4 changes: 3 additions & 1 deletion docs/src/dev/readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Dev...
* Should probably exclude?
* Should probably exclude?
* cli / zsh literally will not pass the \ to node. so it must be escaped
* i.e. cli-escape-lines.md
19 changes: 17 additions & 2 deletions lib/bin_build/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@
* todo think about how to test this properly performance wise
* it's surprisingly not bad. powershell was much slower...
*/
// import process from "node:process";
// import process from "node:process"; //this will break argv for w/e reason
import {win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
// export {win32ToWin32WSL2}

/* take arguments from command line */
const args = process.argv.slice(2);
// might want to check / extract this function
if(process.platform === 'win32'){
console.log(win32ToWin32WSL2(args.join(' ')))
}else{
/** instead of doing this... perhaps it should just be escaped properly */
// have to escape backslash that's not quoted
// const argsJoined = args.join(' ')
const argsJoined = args.join(' ').replace(/\\/g,"\\\\")
//if start and end with quotes, then don't escape
if(/^['"].*?['"]$/.test(argsJoined)){
console.log(win32ToWin32WSL2(argsJoined))
}else{
// console.log(win32ToWin32WSL2(argsJoined.replace(/\\/g,"\\\\")))
console.log(win32ToWin32WSL2(argsJoined))
}
}
// console.log(args);
// console.log(win32ToWin32WSL2(args[0]))
console.log(win32ToWin32WSL2(args.join(' ')))
process.exit(0)
17 changes: 17 additions & 0 deletions lib/test-utils/ConstPathTests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const WSLPassTests = [
["C:\\Users\\Public\\Documents","/mnt/c/Users/Public/Documents"],//maybe append with quotes instead?
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
["C:\\\\Users\\\\Public\\\\Documents","/mnt/c/Users/Public/Documents"],
//todo look into thje backtick
// ["C:\\Users\\Public\\temp` spaces\\a\\b` c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
]
//should work with changing the length of the array
const ogLength = WSLPassTests.length
for (let i = 0; i < ogLength; i++) {
const row = WSLPassTests[i];
row[2] = i;
WSLPassTests.push([`'${row[0]}'`,row[1],`${i}1`]);//append with single quotes
WSLPassTests.push([`"${row[0]}"`,row[1],`${i}2`]);//append with double quotes

}
37 changes: 36 additions & 1 deletion lib/test-utils/mocha-cli-exec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import assert from "node:assert";
* factory function
*/
/**
*
* @deprecated with function below
* @param pathToExe
* @param args
* @param options
Expand Down Expand Up @@ -34,4 +34,39 @@ export function createMochaCliExe(pathToExe,args=[],options={}){
assert.strictEqual(actual,expectedValue);
}

}

/**
* Revised Factory Creator. can replace the top
* can rename to somethuign like strictEqual
*/
export function createMochaCliExeNew(pathToExe,args=[],options={}){
//todo add better defaulting etc... didnt think i neeeded to modify the input
const actualOptions = {shell:true,...options}

/**
* @param inputToTest {string|string[]|object[]}
* @param expectedValue {string|object}
*/
return function(inputToTest,expectedValue){
const argsInput = [...args];//fake copy
if(Array.isArray(inputToTest)){
argsInput.push(...inputToTest);
}else{
argsInput.push(inputToTest);
}
const output = spawnSync(
`"${pathToExe}"`,argsInput,actualOptions
);
if(output.status !== 0){
console.error(output);
console.log(output.stdout.toString())
console.error(output.stderr.toString())
throw new Error("status not 0");
}
const actual = output.stdout.toString().trim();
console.assert(actual === expectedValue,`inputToTest: ${inputToTest}`)
assert.strictEqual(actual,expectedValue);
}

}
Loading