-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(textlint-script): support
import()
(#1284)
* feat(textlint-script): support `import()` textlint-script should not transpile `import()` to `require()`. It will be required for ESM support. * remove unused test * test: normalize path
- Loading branch information
Showing
10 changed files
with
178 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/textlint-scripts/example-dynamic-import/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Debug log from npm | ||
npm-debug.log | ||
|
||
|
||
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
|
||
/lib |
14 changes: 14 additions & 0 deletions
14
packages/textlint-scripts/example-dynamic-import/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "textlint-scripts-example-dynamic-import", | ||
"version": "13.3.2", | ||
"private": true, | ||
"scripts": { | ||
"build": "textlint-scripts build", | ||
"test": "textlint-scripts test" | ||
}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"textlint-scripts": "^13.3.2" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/textlint-scripts/example-dynamic-import/src/esm-worker.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function esmWorker() { | ||
return "from esm"; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/textlint-scripts/example-dynamic-import/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function (context, options = {}) { | ||
const { Syntax, RuleError, report, getSource } = context; | ||
return { | ||
async [Syntax.Document](node) { | ||
const { esmWorker } = await import("./esm-worker.mjs"); | ||
const result = await esmWorker(); | ||
const text = getSource(node); | ||
if (/valid/.test(text)) { | ||
return; | ||
} | ||
report(node, new RuleError(`esmWorker result: ${result}`)); | ||
} | ||
}; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/textlint-scripts/example-dynamic-import/test/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
// See https://github.com/textlint/textlint/tree/master/packages/textlint-tester | ||
import TextLintTester from "textlint-tester"; | ||
// rule | ||
import rule from "../src/index"; | ||
|
||
const tester = new TextLintTester(); | ||
// ruleName, rule, { valid, invalid } | ||
tester.run("rule", rule, { | ||
valid: ["valid"], | ||
invalid: [ | ||
{ | ||
text: "error", | ||
errors: [ | ||
{ | ||
message: "esmWorker result: from esm", | ||
index: 0 | ||
} | ||
] | ||
} | ||
] | ||
}); |
31 changes: 0 additions & 31 deletions
31
packages/textlint-tester/test/textlint-tester-invalid-test.ts
This file was deleted.
Oops, something went wrong.