Skip to content

Add filepath to extract-meta errors #3364

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion dash/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def get_hooks(cls, hook: str):
return cls.hooks.get_hooks(hook)

@classmethod
def register_setuptools(cls):
def register_plugins(cls):
if cls._registered:
# Only have to register once.
return
Expand Down
2 changes: 1 addition & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def _setup_hooks(self):
from ._hooks import HooksManager

self._hooks = HooksManager
self._hooks.register_setuptools()
self._hooks.register_plugins()

for setup in self._hooks.get_hooks("setup"):
setup(self)
Expand Down
4 changes: 2 additions & 2 deletions dash/development/component_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import argparse
import shutil
import functools
import pkg_resources
from importlib import resources
import yaml

from ._r_components_generation import write_class_file
Expand Down Expand Up @@ -57,7 +57,7 @@ def generate_components(

is_windows = sys.platform == "win32"

extract_path = pkg_resources.resource_filename("dash", "extract-meta.js")
extract_path = os.path.join(str(resources.files("dash")), "extract-meta.js")

reserved_patterns = "|".join(f"^{p}$" for p in reserved_words)

Expand Down
32 changes: 24 additions & 8 deletions dash/extract-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function getTsConfigCompilerOptions() {

let failedBuild = false;
const excludedDocProps = ['setProps', 'id', 'className', 'style'];
const errorFiles = [];

const isOptional = prop => (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;

Expand Down Expand Up @@ -91,14 +92,18 @@ function logError(error, filePath) {
if (error instanceof Error) {
process.stderr.write(error.stack + '\n');
}
if (filePath && !errorFiles.includes(filePath)) {
errorFiles.push(filePath);
}
}

function isReservedPropName(propName) {
function isReservedPropName(propName, filepath, baseProp) {
reservedPatterns.forEach(reservedPattern => {
if (reservedPattern.test(propName)) {
process.stderr.write(
`\nERROR: "${propName}" matches reserved word ` +
`pattern: ${reservedPattern.toString()}\n`
logError(
`\nERROR:${filepath}: "${baseProp ? baseProp + "." : ""}${propName}" matches reserved word ` +
`pattern: ${reservedPattern.toString()}\n`,
filepath
);
failedBuild = true;
}
Expand Down Expand Up @@ -140,7 +145,7 @@ function parseJSX(filepath) {
const src = fs.readFileSync(filepath);
const doc = reactDocs.parse(src);
Object.keys(doc.props).forEach(propName =>
isReservedPropName(propName)
isReservedPropName(propName, filepath)
);
docstringWarning(doc);
return doc;
Expand All @@ -152,6 +157,7 @@ function parseJSX(filepath) {
function gatherComponents(sources, components = {}) {
const names = [];
const filepaths = [];
let currentFilepath = "", currentBasePropName = ""; // For debugging purposes.

const gather = filepath => {
if (ignorePattern && ignorePattern.test(filepath)) {
Expand All @@ -166,8 +172,9 @@ function gatherComponents(sources, components = {}) {
filepaths.push(filepath);
names.push(name);
} catch (err) {
process.stderr.write(
`ERROR: Invalid component file ${filepath}: ${err}`
logError(
`ERROR: Invalid component file ${filepath}: ${err}`,
filepath,
);
}
}
Expand Down Expand Up @@ -594,7 +601,11 @@ function gatherComponents(sources, components = {}) {

properties.forEach(prop => {
const name = prop.getName();
if (isReservedPropName(name)) {

if (parentType === null) {
currentBasePropName = name;
}
if (isReservedPropName(name, currentFilepath, currentBasePropName)) {
return;
}
const propType = checker.getTypeOfSymbolAtLocation(
Expand Down Expand Up @@ -660,6 +671,7 @@ function gatherComponents(sources, components = {}) {
};

zipArrays(filepaths, names).forEach(([filepath, name]) => {
currentFilepath = filepath;
const source = program.getSourceFile(filepath);
const moduleSymbol = checker.getSymbolAtLocation(source);
const exports = checker.getExportsOfModule(moduleSymbol);
Expand Down Expand Up @@ -791,5 +803,9 @@ if (!failedBuild) {
process.stdout.write(JSON.stringify(metadata, null, 2));
} else {
logError('extract-meta failed');
logError('Check these files for errors:')
errorFiles.forEach((errorFile) => {
logError(`Error in: ${errorFile}`)
})
process.exit(1);
}
1 change: 0 additions & 1 deletion requirements/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ typing_extensions>=4.1.1
requests
retrying
nest-asyncio
setuptools