Skip to content

Commit

Permalink
Normalize path for windows os (#197)
Browse files Browse the repository at this point in the history
* Normalize path for windows os

* Use url.resolve instead of normalize-path
  • Loading branch information
xcatliu authored and devongovett committed Dec 11, 2017
1 parent 98afb9b commit 6d6f5f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/core/parcel/src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const posthtml = require('posthtml');
const parse = require('posthtml-parser');
const api = require('posthtml/lib/api');
const path = require('path');
const url = require('url');
const md5 = require('../utils/md5');
const render = require('posthtml-render');
const posthtmlTransform = require('../transforms/posthtml');
Expand Down Expand Up @@ -47,7 +48,12 @@ class HTMLAsset extends Asset {
if (elements && elements.includes(node.tag)) {
let assetPath = this.addURLDependency(node.attrs[attr]);
if (!isURL(assetPath)) {
assetPath = path.join(this.options.publicURL, assetPath);
// Use url.resolve to normalize path for windows
// from \path\to\res.js to /path/to/res.js
assetPath = url.resolve(
path.join(this.options.publicURL, assetPath),
''
);
}
node.attrs[attr] = assetPath;
this.isAstDirty = true;
Expand Down
6 changes: 5 additions & 1 deletion packages/core/parcel/src/packagers/HTMLPackager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Packager = require('./Packager');
const posthtml = require('posthtml');
const path = require('path');
const url = require('url');

class HTMLPackager extends Packager {
async addAsset(asset) {
Expand Down Expand Up @@ -39,7 +40,10 @@ class HTMLPackager extends Packager {
tag: 'link',
attrs: {
rel: 'stylesheet',
href: path.join(this.options.publicURL, path.basename(bundle.name))
href: url.resolve(
path.join(this.options.publicURL, path.basename(bundle.name)),
''
)
}
});
}
Expand Down
7 changes: 4 additions & 3 deletions packages/core/parcel/src/packagers/RawPackager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Packager = require('./Packager');
const fs = require('../utils/fs');
const path = require('path');
const url = require('url');

class RawPackager extends Packager {
// Override so we don't create a file for this bundle.
Expand All @@ -11,9 +12,9 @@ class RawPackager extends Packager {
// Use the bundle name if this is the entry asset, otherwise generate one.
let name = this.bundle.name;
if (asset !== this.bundle.entryAsset) {
name = path.join(
path.dirname(this.bundle.name),
asset.generateBundleName()
name = url.resolve(
path.join(path.dirname(this.bundle.name), asset.generateBundleName()),
''
);
}

Expand Down

0 comments on commit 6d6f5f0

Please sign in to comment.