Skip to content

Commit 80e5be2

Browse files
committed
feat(orderwarning): ignore plugins included by their local paths
Newer versions of TS only allow plugins to be specified by package name. Dropped the tests and the code for guessing when the plugin is included via a local path. This will make no difference to anyone using the plugin normally via npm, and won't make any difference to properly set up projects.
1 parent 6825360 commit 80e5be2

File tree

3 files changed

+8
-44
lines changed

3 files changed

+8
-44
lines changed

src/orderwarning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function getThisPluginNode(ts, pluginsArrayNode) {
3030
return false;
3131
}
3232
const nameAssignments = getChildren(node, false, ts.SyntaxKind.PropertyAssignment).filter(node => node.name.text === 'name')
33-
return nameAssignments.some(node => node.initializer.kind === ts.SyntaxKind.StringLiteral && /(^|\\|\/)vs-compat-ts-plugin($|\\|\/)/.test(node.initializer.text));
33+
return nameAssignments.some(node => node.initializer.kind === ts.SyntaxKind.StringLiteral && node.initializer.text === 'vs-compat-ts-plugin');
3434
})[0];
3535
}
3636

test/fixtures/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
THIS_PLUGIN: {
55
name: 'vs-compat-ts-plugin',
66
path: 'vs-compat-ts-plugin',
7-
namelessPath: '../index.js' // For loading the plugin without having the package name in the path
7+
namelessPath: '../../../../../index.js' // For loading the plugin without having the package name in the path
88
},
99
LOG_CWD_PLUGIN: {
1010
name: 'logCwdPlugin', path: '@vs-compat-ts-plugin/log-cwd-plugin'

test/orderwarning.spec.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pluginTest('should log but not warn if plugin cannot be found in the list', {
2525
pluginTest('should warn when something precedes this plugin in plugins list', {
2626
plugins: [
2727
{ name: 'other-plugin' },
28-
{ name: THIS_PLUGIN.name },
29-
{ name: THIS_PLUGIN.namelessPath }
28+
{ name: THIS_PLUGIN.name }
3029
],
3130
serverCommands: getTsConfigDiagnostics,
3231
check: (t, { responses }) => {
@@ -39,8 +38,7 @@ pluginTest('should warn when something precedes this plugin in plugins list', {
3938
pluginTest('should not warn when this plugin is first in plugins list', {
4039
plugins: [
4140
{ name: THIS_PLUGIN.name },
42-
{ name: 'other-plugin' },
43-
{ name: THIS_PLUGIN.namelessPath }
41+
{ name: 'other-plugin' }
4442
],
4543
serverCommands: getTsConfigDiagnostics,
4644
check: (t, { responses }) => {
@@ -52,8 +50,7 @@ pluginTest('should not warn when this plugin is first in plugins list', {
5250
pluginTest('should not warn when found outside the normal plugins list', {
5351
plugins: [
5452
{ name: THIS_PLUGIN.name },
55-
{ name: 'other-plugin', config: { plugins: [{ name: THIS_PLUGIN.name }] } },
56-
{ name: THIS_PLUGIN.namelessPath }
53+
{ name: 'other-plugin', config: { plugins: [{ name: THIS_PLUGIN.name }] } }
5754
],
5855
serverCommands: getTsConfigDiagnostics,
5956
check: (t, { responses }) => {
@@ -65,8 +62,7 @@ pluginTest('should not warn when found outside the normal plugins list', {
6562
pluginTest('should mark error across the whole plugin def object in the source', {
6663
plugins: [
6764
{ name: 'other-plugin' },
68-
{ name: THIS_PLUGIN.name },
69-
{ name: THIS_PLUGIN.namelessPath }
65+
{ name: THIS_PLUGIN.name }
7066
],
7167
serverCommands: getTsConfigDiagnostics,
7268
check: (t, { responses }) => {
@@ -83,8 +79,7 @@ pluginTest('should mark error across the whole plugin def object in the source',
8379
pluginTest('should be warning with a sensible message', {
8480
plugins: [
8581
{ name: 'other-plugin' },
86-
{ name: THIS_PLUGIN.name },
87-
{ name: THIS_PLUGIN.namelessPath }
82+
{ name: THIS_PLUGIN.name }
8883
],
8984
serverCommands: getTsConfigDiagnostics,
9085
check: (t, { responses }) => {
@@ -99,36 +94,7 @@ pluginTest('should be warning with a sensible message', {
9994
pluginTest('should find the plugin by its package name', {
10095
plugins: [
10196
{ name: 'other-plugin' },
102-
{ name: THIS_PLUGIN.name },
103-
{ name: THIS_PLUGIN.namelessPath }
104-
],
105-
serverCommands: getTsConfigDiagnostics,
106-
check: (t, { responses }) => {
107-
t.ok(responses[0].success);
108-
t.equal(responses[0].body.length, 1);
109-
t.equal(responses[0].body[0].code, EXPECTED_ERROR_CODE);
110-
}
111-
});
112-
113-
pluginTest('should find the plugin in local paths', {
114-
plugins: [
115-
{ name: 'other-plugin' },
116-
{ name: path.join('..', THIS_PLUGIN.name) },
117-
{ name: THIS_PLUGIN.namelessPath }
118-
],
119-
serverCommands: getTsConfigDiagnostics,
120-
check: (t, { responses }) => {
121-
t.ok(responses[0].success);
122-
t.equal(responses[0].body.length, 1);
123-
t.equal(responses[0].body[0].code, EXPECTED_ERROR_CODE);
124-
}
125-
});
126-
127-
pluginTest('should find the plugin when requesting a specific file', {
128-
plugins: [
129-
{ name: 'other-plugin' },
130-
{ name: path.join(THIS_PLUGIN.name, 'index.js') },
131-
{ name: THIS_PLUGIN.namelessPath }
97+
{ name: THIS_PLUGIN.name }
13298
],
13399
serverCommands: getTsConfigDiagnostics,
134100
check: (t, { responses }) => {
@@ -140,7 +106,6 @@ pluginTest('should find the plugin when requesting a specific file', {
140106

141107
pluginTest('should not find the plugin when it appears in another plugin name', {
142108
plugins: [
143-
{ name: THIS_PLUGIN.namelessPath },
144109
{ name: 'not-vs-compat-ts-plugin' }
145110
],
146111
serverCommands: getTsConfigDiagnostics,
@@ -154,7 +119,6 @@ pluginTest('should be ok with the plugin appearing twice if one comes first', {
154119
plugins: [
155120
{ name: THIS_PLUGIN.name },
156121
{ name: THIS_PLUGIN.name },
157-
{ name: THIS_PLUGIN.namelessPath }
158122
],
159123
serverCommands: getTsConfigDiagnostics,
160124
check: (t, { responses }) => {

0 commit comments

Comments
 (0)