From c60f59c28b7bede9f449927427bb62305386f9c0 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 12 Nov 2020 00:11:07 -0600 Subject: [PATCH 1/5] Added an index.d.ts file and support for ESM modules --- index.d.ts | 3 +++ index.mjs | 36 ++++++++++++++++++++++++++++++++++++ package.json | 10 +++++++++- test.js => test/test.js | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 index.d.ts create mode 100644 index.mjs rename test.js => test/test.js (98%) diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..bedccf0 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +declare const normalize: (path: string, stripTrailing?: boolean) => string; + +export default normalize; \ No newline at end of file diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..64eb781 --- /dev/null +++ b/index.mjs @@ -0,0 +1,36 @@ + +/*! + * normalize-path + * + * Copyright (c) 2014-2018, Jon Schlinkert. + * Released under the MIT License. + */ + +export default function(path, stripTrailing) { + if (typeof path !== 'string') { + throw new TypeError('expected path to be a string'); + } + + if (path === '\\' || path === '/') return '/'; + + var len = path.length; + if (len <= 1) return path; + + // ensure that win32 namespaces has two leading slashes, so that the path is + // handled properly by the win32 version of path.parse() after being normalized + // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces + var prefix = ''; + if (len > 4 && path[3] === '\\') { + var ch = path[2]; + if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') { + path = path.slice(2); + prefix = '//'; + } + } + + var segs = path.split(/[/\\]+/); + if (stripTrailing !== false && segs[segs.length - 1] === '') { + segs.pop(); + } + return prefix + segs.join('/'); +} diff --git a/package.json b/package.json index ad61098..54956f6 100644 --- a/package.json +++ b/package.json @@ -8,21 +8,29 @@ "Blaine Bublitz (https://twitter.com/BlaineBublitz)", "Jon Schlinkert (http://twitter.com/jonschlinkert)" ], - "repository": "jonschlinkert/normalize-path", + "repository": "https://github.com/jonschlinkert/normalize-path", "bugs": { "url": "https://github.com/jonschlinkert/normalize-path/issues" }, "license": "MIT", "files": [ + "index.mjs", "index.js" ], "main": "index.js", + "exports": { + "import": "./index.mjs", + "require": "./index.js" + }, + "type": "commonjs", + "typing": "index.d.ts", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, + "dependencies": {}, "devDependencies": { "gulp-format-md": "^1.0.0", "minimist": "^1.2.0", diff --git a/test.js b/test/test.js similarity index 98% rename from test.js rename to test/test.js index 55b3bda..6a7c5a9 100644 --- a/test.js +++ b/test/test.js @@ -11,7 +11,7 @@ require('mocha'); var path = require('path'); var argv = require('minimist')(process.argv.slice(2)); var assert = require('assert'); -var normalize = require('./'); +var normalize = require('../'); if (argv.bench) { var b = path.join(__dirname, 'benchmark/code', argv.bench); From 67750e0d3503938f0b79f7a6fb681bc3033dc840 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 12 Nov 2020 00:41:53 -0600 Subject: [PATCH 2/5] Had to change package.json's dependency versions --- index.mjs => index.cjs | 5 ++--- index.js | 5 +++-- package.json | 18 +++++++++--------- test/{test.js => test.cjs} | 0 4 files changed, 14 insertions(+), 14 deletions(-) rename index.mjs => index.cjs (94%) rename test/{test.js => test.cjs} (100%) diff --git a/index.mjs b/index.cjs similarity index 94% rename from index.mjs rename to index.cjs index 64eb781..6fac553 100644 --- a/index.mjs +++ b/index.cjs @@ -1,4 +1,3 @@ - /*! * normalize-path * @@ -6,7 +5,7 @@ * Released under the MIT License. */ -export default function(path, stripTrailing) { +module.exports = function(path, stripTrailing) { if (typeof path !== 'string') { throw new TypeError('expected path to be a string'); } @@ -33,4 +32,4 @@ export default function(path, stripTrailing) { segs.pop(); } return prefix + segs.join('/'); -} +}; diff --git a/index.js b/index.js index 6fac553..64eb781 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ + /*! * normalize-path * @@ -5,7 +6,7 @@ * Released under the MIT License. */ -module.exports = function(path, stripTrailing) { +export default function(path, stripTrailing) { if (typeof path !== 'string') { throw new TypeError('expected path to be a string'); } @@ -32,4 +33,4 @@ module.exports = function(path, stripTrailing) { segs.pop(); } return prefix + segs.join('/'); -}; +} diff --git a/package.json b/package.json index 54956f6..28e586f 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,15 @@ }, "license": "MIT", "files": [ - "index.mjs", - "index.js" + "index.js", + "index.cjs" ], - "main": "index.js", + "main": "index.cjs", "exports": { - "import": "./index.mjs", - "require": "./index.js" + "import": "./index.js", + "require": "./index.cjs" }, - "type": "commonjs", + "type": "module", "typing": "index.d.ts", "engines": { "node": ">=0.10.0" @@ -32,9 +32,9 @@ }, "dependencies": {}, "devDependencies": { - "gulp-format-md": "^1.0.0", - "minimist": "^1.2.0", - "mocha": "^3.5.3" + "gulp-format-md": "^2.0.0", + "minimist": "^1.2.5", + "mocha": "^8.2.1" }, "keywords": [ "absolute", diff --git a/test/test.js b/test/test.cjs similarity index 100% rename from test/test.js rename to test/test.cjs From 22f549197095e537462586072494b4d6faed0a57 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 12 Nov 2020 00:43:59 -0600 Subject: [PATCH 3/5] Renamed example.js to example.cjs --- example.js => example.cjs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename example.js => example.cjs (100%) diff --git a/example.js b/example.cjs similarity index 100% rename from example.js rename to example.cjs From 0e4b08ca041348c1ad3a95006421ea5cb4901fe9 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 12 Nov 2020 01:19:24 -0600 Subject: [PATCH 4/5] Changed benchmark files' extension to cjs For some reason, I couldn't get the benchmark files to even run. Not sure if it really matters to the original authors though. --- benchmark/code/{current.js => current.cjs} | 0 benchmark/code/{no-regex.js => no-regex.cjs} | 0 benchmark/code/{node-path.js => node-path.cjs} | 0 benchmark/code/{regex.js => regex.cjs} | 0 benchmark/code/{split.js => split.cjs} | 0 benchmark/code/{v2.js => v2.cjs} | 0 benchmark/code/{while.js => while.cjs} | 0 benchmark/fixtures/{long.js => long.cjs} | 0 benchmark/fixtures/{short.js => short.cjs} | 0 benchmark/fixtures/{single.js => single.cjs} | 0 benchmark/fixtures/{trailing.js => trailing.cjs} | 0 benchmark/fixtures/{unix.js => unix.cjs} | 0 benchmark/fixtures/{win.js => win.cjs} | 0 benchmark/fixtures/{win32-namespace.js => win32-namespace.cjs} | 0 benchmark/{index.js => index.cjs} | 2 +- 15 files changed, 1 insertion(+), 1 deletion(-) rename benchmark/code/{current.js => current.cjs} (100%) rename benchmark/code/{no-regex.js => no-regex.cjs} (100%) rename benchmark/code/{node-path.js => node-path.cjs} (100%) rename benchmark/code/{regex.js => regex.cjs} (100%) rename benchmark/code/{split.js => split.cjs} (100%) rename benchmark/code/{v2.js => v2.cjs} (100%) rename benchmark/code/{while.js => while.cjs} (100%) rename benchmark/fixtures/{long.js => long.cjs} (100%) rename benchmark/fixtures/{short.js => short.cjs} (100%) rename benchmark/fixtures/{single.js => single.cjs} (100%) rename benchmark/fixtures/{trailing.js => trailing.cjs} (100%) rename benchmark/fixtures/{unix.js => unix.cjs} (100%) rename benchmark/fixtures/{win.js => win.cjs} (100%) rename benchmark/fixtures/{win32-namespace.js => win32-namespace.cjs} (100%) rename benchmark/{index.js => index.cjs} (78%) diff --git a/benchmark/code/current.js b/benchmark/code/current.cjs similarity index 100% rename from benchmark/code/current.js rename to benchmark/code/current.cjs diff --git a/benchmark/code/no-regex.js b/benchmark/code/no-regex.cjs similarity index 100% rename from benchmark/code/no-regex.js rename to benchmark/code/no-regex.cjs diff --git a/benchmark/code/node-path.js b/benchmark/code/node-path.cjs similarity index 100% rename from benchmark/code/node-path.js rename to benchmark/code/node-path.cjs diff --git a/benchmark/code/regex.js b/benchmark/code/regex.cjs similarity index 100% rename from benchmark/code/regex.js rename to benchmark/code/regex.cjs diff --git a/benchmark/code/split.js b/benchmark/code/split.cjs similarity index 100% rename from benchmark/code/split.js rename to benchmark/code/split.cjs diff --git a/benchmark/code/v2.js b/benchmark/code/v2.cjs similarity index 100% rename from benchmark/code/v2.js rename to benchmark/code/v2.cjs diff --git a/benchmark/code/while.js b/benchmark/code/while.cjs similarity index 100% rename from benchmark/code/while.js rename to benchmark/code/while.cjs diff --git a/benchmark/fixtures/long.js b/benchmark/fixtures/long.cjs similarity index 100% rename from benchmark/fixtures/long.js rename to benchmark/fixtures/long.cjs diff --git a/benchmark/fixtures/short.js b/benchmark/fixtures/short.cjs similarity index 100% rename from benchmark/fixtures/short.js rename to benchmark/fixtures/short.cjs diff --git a/benchmark/fixtures/single.js b/benchmark/fixtures/single.cjs similarity index 100% rename from benchmark/fixtures/single.js rename to benchmark/fixtures/single.cjs diff --git a/benchmark/fixtures/trailing.js b/benchmark/fixtures/trailing.cjs similarity index 100% rename from benchmark/fixtures/trailing.js rename to benchmark/fixtures/trailing.cjs diff --git a/benchmark/fixtures/unix.js b/benchmark/fixtures/unix.cjs similarity index 100% rename from benchmark/fixtures/unix.js rename to benchmark/fixtures/unix.cjs diff --git a/benchmark/fixtures/win.js b/benchmark/fixtures/win.cjs similarity index 100% rename from benchmark/fixtures/win.js rename to benchmark/fixtures/win.cjs diff --git a/benchmark/fixtures/win32-namespace.js b/benchmark/fixtures/win32-namespace.cjs similarity index 100% rename from benchmark/fixtures/win32-namespace.js rename to benchmark/fixtures/win32-namespace.cjs diff --git a/benchmark/index.js b/benchmark/index.cjs similarity index 78% rename from benchmark/index.js rename to benchmark/index.cjs index 041d09c..6ee2393 100644 --- a/benchmark/index.js +++ b/benchmark/index.cjs @@ -5,7 +5,7 @@ const suite = require('benchmarked'); const argv = process.argv.slice(2); const code = argv[0] || '{current,v2}'; -suite.run({ code: `code/${code}.js`, fixtures: 'fixtures/*.js' }) +suite.run({ code: `code/${code}.cjs`, fixtures: 'fixtures/*.cjs' }) .then(function(stats) { console.log(suite.render(stats)); }) From fec6ea0ba62ea842b15ca3722af13918db3f5684 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 12 Nov 2020 13:10:31 -0600 Subject: [PATCH 5/5] Updated travis.yml See https://nodejs.medium.com/choosing-the-node-js-versions-for-your-ci-tests-hint-use-lts-89b67f68d7ca for why. --- .travis.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1686664..c7f2be8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,6 @@ os: language: node_js node_js: - node - - '9' - - '8' - - '7' - - '6' - - '5' - - '4' - - '0.12' - - '0.10' + - lts/* + - '12' + - '10' \ No newline at end of file