Skip to content
Browse files

First test committed.

  • Loading branch information...
1 parent 80543b8 commit f1505ee202ce30e169288cc133e14a7f3b4abbca @jrburke jrburke committed Jun 21, 2012
Showing with 2,237 additions and 2 deletions.
  1. +58 −0 LICENSE
  2. +26 −2 README.md
  3. +4 −0 tests/case/CamelCase.js
  4. +19 −0 tests/case/case.html
  5. +11 −0 tests/case/main.js
  6. +3 −0 tests/case/other/camelCase.js
  7. +2,037 −0 tests/require.js
  8. +79 −0 xrayquire.js
View
58 LICENSE
@@ -0,0 +1,58 @@
+xrayquire is released under two licenses: new BSD, and MIT. You may pick the
+license that best suits your development needs. The text of both licenses are
+provided below.
+
+
+The "New" BSD License:
+----------------------
+
+Copyright (c) 2012, The Dojo Foundation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Dojo Foundation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+MIT License
+-----------
+
+Copyright (c) 2012, The Dojo Foundation
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
28 README.md
@@ -1,4 +1,28 @@
-Just a placeholder for now. The issue tracker will be used to track items to consider for it.
+# xrayrequire
-The idea is for it to be a helper script that plugs into the requirejs internals to give information on what is going on, and hopefully some pointers on possible errors.
+An introspection tool for RequireJS. It dives into the the internals of
+RequireJS to show you information on the modules you load and flags some
+potential problems.
+This is still under development. See the
+[issues area](https://github.com/requirejs/xrayquire/issues) for the features
+that it may support in the future.
+
+See the tests directory for examples of the items xrayrequire checks.
+
+## Usage
+
+Place it as a script tag right after require.js:
+
+```html
+<script src="require.js"></script>
+<script src="xrayrequire.js"></script>
+```
+
+## Error checks
+
+### Case insensitive ID collisions
+
+Checks for module IDs that differ only by case, which indicates a probable
+typing error, or something that will lead to problems on case insensitive
+operating systems.
View
4 tests/case/CamelCase.js
@@ -0,0 +1,4 @@
+define({
+ name: 'CamelCase'
+});
+
View
19 tests/case/case.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Case-insensitive test</title>
+ <script data-main="main" src="../require.js"></script>
+ <script src="../../xrayquire"></script>
+</head>
+<body>
+ <h1>Case-insensitive test</h1>
+
+ <p>Tests if there are module IDs that only differ in
+ string case. May indicate a typo or a problem that
+ will show up when moving to a case-insensitive file
+ system.</p>
+
+ <p>In the console, there should be an error printed about
+ a case issue.</p>
+</body>
+</html>
View
11 tests/case/main.js
@@ -0,0 +1,11 @@
+requirejs.config({
+ paths: {
+ 'camelCase': 'other/camelCase'
+ }
+});
+
+require(['CamelCase', 'camelCase'], function (CamelCase, camelCase) {
+ console.log(CamelCase);
+ console.log(camelCase);
+});
+
View
3 tests/case/other/camelCase.js
@@ -0,0 +1,3 @@
+define({
+ name: 'cameCase'
+});
View
2,037 tests/require.js
2,037 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
79 xrayquire.js
@@ -0,0 +1,79 @@
+/**
+ * @license xrayquire 0.0.0 Copyright (c) 2012, The Dojo Foundation All Rights Reserved.
+ * Available via the MIT or new BSD license.
+ * see: http://github.com/requirejs/xrayquire for details
+ */
+/*jslint */
+/*global requirejs, xrayquire, console */
+
+/**
+ * Put a script tag in the HTML that references this script right after the
+ * script tag for require.js.
+ */
+
+(function () {
+ 'use strict';
+
+ var contexts = {},
+ config = typeof xrayquire === 'undefined' ? {} : xrayquire,
+ s = requirejs.s,
+ oldNewContext = s.newContext,
+ prop;
+
+ function getX(context) {
+ if (!context.xray) {
+ context.xray = {
+ traced: {},
+ mixedCases: {}
+ };
+ }
+ return context.xray;
+ }
+
+ function modContext(context) {
+ var oldLoad = context.load;
+
+ context.load = function (id, url) {
+ var lowerId = id.toLowerCase(),
+ mixedCases = getX(context).mixedCases;
+
+ if (mixedCases[lowerId]) {
+ console.error('Mixed case modules may conflict: ' + mixedCases[lowerId] + ' vs. ' + id);
+ } else {
+ mixedCases[lowerId] = id;
+ }
+
+ return oldLoad.apply(context, arguments);
+ };
+
+ return context;
+ }
+
+ //Mod any existing contexts.
+ for (prop in requirejs.s.contexts) {
+ if (s.contexts.hasOwnProperty(prop)) {
+ modContext(s.contexts[prop]);
+ }
+ }
+ //Apply mods to any new context.
+ s.newContext = function (name) {
+ return modContext(oldNewContext);
+ };
+
+ requirejs.onResourceLoad = function (context, map, deps) {
+ var xray = getX(context),
+ id = map.id;
+
+ if (typeof context.defined[id] === 'undefined') {
+ //May be a problem with a circular dependency.
+ //console.error(id + ' has undefined module value, may be part of a bad circular reference');
+ }
+
+ xray.traced[id] = {
+ map: map,
+ deps: deps
+ };
+ };
+
+
+}());

0 comments on commit f1505ee

Please sign in to comment.
Something went wrong with that request. Please try again.