Skip to content

Commit

Permalink
Move away from posix (OctoLinker#428)
Browse files Browse the repository at this point in the history
This fixes OctoLinker#427 by mocking path.join
  • Loading branch information
stefanbuck authored and josephfrazier committed Jan 3, 2018
1 parent d947051 commit 1086810
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions __mocks__/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require.requireActual('path');

path.join = path.posix.join;

module.exports = path;
4 changes: 2 additions & 2 deletions lib/plugins/go.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { posix, dirname } from 'path';
import { join, dirname } from 'path';
import { go } from '../../packages/helper-grammar-regex-collection/index.js';

function goFile({ path, target }) {
const list = [];
const basePath = posix.join(dirname(path), target);
const basePath = join(dirname(path), target);
const filename = target.slice(target.lastIndexOf('/') + 1);

list.push(`/${filename}.go`);
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/javascript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { posix, dirname, extname } from 'path';
import { join, dirname, extname } from 'path';
import concatMap from 'concat-map';
import {
REQUIRE,
Expand All @@ -21,7 +21,7 @@ function getTopModuleName(target) {
export function javascriptFile({ path, target }) {
const list = [];
const extName = ['.js', '.jsx', '.ts', '.tsx', '.ls', '.json'];
const basePath = posix.join(dirname(path), target);
const basePath = join(dirname(path), target);
const pathExt = extname(path);
const fileExt = extname(basePath);

Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/nodejs-relative-path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { posix, dirname } from 'path';
import { join, dirname } from 'path';
import {
NODEJS_RELATIVE_PATH,
NODEJS_RELATIVE_PATH_JOIN,
Expand All @@ -10,7 +10,7 @@ export default {
name: 'NodejsRelativePath',

resolve({ target, path }) {
return `{BASE_URL}${posix.join(dirname(path), target)}`;
return `{BASE_URL}${join(dirname(path), target)}`;
},

getPattern() {
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/ruby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { posix } from 'path';
import { join } from 'path';
import { REQUIRE } from '../../packages/helper-grammar-regex-collection/index.js';
import liveResolverQuery from '../resolver/live-resolver-query.js';

Expand All @@ -11,9 +11,9 @@ export default {
// https://github.com/github/pages-gem/blob/master/lib/github-pages/dependencies.rb

if (isPath) {
const basePath = posix.join(path.split('/lib/')[0], 'lib');
const basePath = join(path.split('/lib/')[0], 'lib');

return `{BASE_URL}${posix.join(basePath, `${target}.rb`)}`;
return `{BASE_URL}${join(basePath, `${target}.rb`)}`;
}

return [liveResolverQuery({ type: 'rubygems', target })];
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/sass.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { posix } from 'path';
import { join } from 'path';
import pathParse from 'path-parse';
import { CSS_IMPORT } from '../../packages/helper-grammar-regex-collection/index.js';
import relativeFile from '../resolver/relative-file.js';
Expand All @@ -9,7 +9,7 @@ export default {

resolve({ path, target }) {
const { dir, name } = pathParse(target);
const prefixedTarget = posix.join(dir, `_${name}`);
const prefixedTarget = join(dir, `_${name}`);

return [
relativeFile({ path, target: `${prefixedTarget}.scss` }),
Expand Down
4 changes: 2 additions & 2 deletions lib/resolver/relative-file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { posix, dirname } from 'path';
import { join, dirname } from 'path';

export default function({ path, target }) {
return `{BASE_URL}${posix.join(dirname(path), target)}`;
return `{BASE_URL}${join(dirname(path), target)}`;
}
2 changes: 2 additions & 0 deletions test/_setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs';
import path from 'path';

jest.mock('path');

global.chrome = {};
global.chrome.runtime = {
sendMessage: jest.fn(),
Expand Down

0 comments on commit 1086810

Please sign in to comment.