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

remove path and url node dependencies from main entry points #105

Merged
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
6 changes: 2 additions & 4 deletions src/jsx-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import escodegen from 'escodegen';
import fs from 'fs';
import jsx from 'acorn-jsx';
import { parse, parseFragment, serialize } from 'parse5';
import path from 'path';
import { URL, pathToFileURL } from 'url';

const baseURL = pathToFileURL(`${process.cwd()}/`).href;
const baseURL = new URL(`file://${process.cwd()}/`);
const jsxRegex = /\.(jsx)$/;

// TODO same hack as definitions
Expand All @@ -25,7 +23,7 @@ function getParse(html) {
}

export function getParser(moduleURL) {
const isJSX = path.extname(moduleURL.pathname) === '.jsx';
const isJSX = moduleURL.pathname.split('.').pop() === 'jsx';

if (!isJSX) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import escodegen from 'escodegen';
import { getParser, parseJsx } from './jsx-loader.js';
import { parse, parseFragment, serialize } from 'parse5';
import fs from 'fs';
import path from 'path';

function getParse(html) {
return html.indexOf('<html>') >= 0 || html.indexOf('<body>') >= 0 || html.indexOf('<head>') >= 0
Expand Down Expand Up @@ -74,9 +73,10 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
ImportDeclaration(node) {
const specifier = node.source.value;
const isBareSpecifier = specifier.indexOf('.') !== 0 && specifier.indexOf('/') !== 0;
const extension = specifier.split('.').pop();

// TODO would like to decouple .jsx from the core, ideally
if (!isBareSpecifier && ['.js', '.jsx'].includes(path.extname(specifier))) {
if (!isBareSpecifier && ['js', 'jsx'].includes(extension)) {
const dependencyModuleURL = new URL(node.source.value, moduleURL);

registerDependencies(dependencyModuleURL, definitions, nextDepth);
Expand Down